home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / blindDataEditor.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  192.6 KB  |  6,994 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. global int            $bdeNumUdAttrsUsed            = 5;
  18.  
  19. global int            $bdeBinaryMode                = 0;
  20. global int            $bdeDiscreteValueMode        = 1;
  21. global int            $bdeDiscreteRangeMode        = 2;
  22. global int            $bdeHexSetMode                = 3;
  23. global int            $bdeHesNotSetMode            = 4;
  24. global int            $bdeHesEqualMode            = 5;
  25. global int            $bdeContinuousMode            = 6;
  26. global int            $bdeAsColorMode                = 7;
  27.  
  28. global string        $bdeDiscreteValName = "discrete value";
  29. global string        $bdeDiscreteRangeName = "discrete range";
  30. global string        $bdeHexValName = "hex";
  31. global string        $bdeContinuousName = "continuous";
  32. global string        $bdeAsColorName = "as color";
  33.  
  34. global string        $bdeTPresetLayout;
  35. global string        $bdeQueryColorLayout;
  36.  
  37. global int            $bdeVSSJ = -1;
  38.  
  39. // For debugging purposes
  40. proc printCol( float $col[] )
  41. {
  42.     print( "Color is: ( " + $col[0] + ", " + $col[1] + ", " + $col[2] + ")\n" );
  43. }
  44.  
  45. // Math utils
  46. proc int round( float $val )
  47. {
  48.     float $floor = floor( $val );
  49.     if ( $val - $floor < .5 )
  50.         return $floor;
  51.     else
  52.         return ( $floor + 1 );
  53. }
  54.  
  55. proc int power( int $x, int $y )
  56. {
  57.     int $newVal = 1;
  58.  
  59.     for ( $i = 0; $i < $y; $i++ )
  60.     {
  61.         $newVal *= $x;
  62.     }
  63.  
  64.     return $newVal;
  65. }
  66.  
  67. // A bunch of utils to convert a 'hex string' to an int and back
  68. // If user's working with hex data they don't want to see the 
  69. // int equivalent, but mel doesn't have any support for hex representations
  70. // of data, so we do it internally
  71.  
  72. // This one's a utility function for the others
  73. proc int getHexInt( string $char )
  74. {
  75.     if ( $char == "A" || $char == "a" )
  76.         return 10;
  77.     else if ( $char == "B" || $char == "b" )
  78.         return 11;
  79.     else if ( $char == "C" || $char == "c" )
  80.         return 12;
  81.     else if ( $char == "D" || $char == "d" )
  82.         return 13;
  83.     else if ( $char == "E" || $char == "e" )
  84.         return 14;
  85.     else if ( $char == "F" || $char == "f" )
  86.         return 15;
  87.     else
  88.     {
  89.         int $val = $char;
  90.         return $val;
  91.     }
  92. }
  93.  
  94. // Another utility function 
  95. // gets the hex char for a single digit (i.e. <= 15)
  96. proc string getHexChar( int $val )
  97. {
  98.     if ( $val > 15 || $val < 0 )
  99.         return "x";
  100.  
  101.     if ( $val < 10 )
  102.     {
  103.         string $ret = $val;
  104.         return $ret;
  105.     }
  106.  
  107.     switch ( $val )
  108.     {
  109.     case 10:
  110.         return "A";
  111.     case 11:
  112.         return "B";
  113.     case 12:
  114.         return "C";
  115.     case 13:
  116.         return "D";
  117.     case 14:
  118.         return "E";
  119.     case 15:
  120.         return "F";
  121.     default:
  122.         return "x";
  123.     }
  124. }
  125.  
  126. // This func gets the char from the string at the specified index
  127. proc string getChar( string $str, int $index )
  128. {
  129.     if ( size( $str ) < $index || 0 >= $index )
  130.         return "";
  131.  
  132.     string $ret = `substring $str $index $index`;
  133.     return $ret;
  134. }
  135.  
  136. proc int isHexString( string $str )
  137. {
  138.     string $sub = `substring $str 1 2`;
  139.     if ( $sub == "0x" || $sub == "0X" )
  140.         return 1;
  141.     else
  142.         return 0;
  143. }
  144.  
  145. // Takes a hex string and returns an int
  146. // This func does no checking on whether the given
  147. // string is the right format or not, so care should be taken when
  148. // using it.
  149. proc int hexStringToInt( string $hex )
  150. {
  151.     int $size = size( $hex );
  152.     string $char;
  153.     int $value = 0;
  154.     int $newVal;
  155.     int $power;
  156.  
  157.     for ( $i = $size; $i > 0; --$i )
  158.     {
  159.         $char = getChar( $hex, $i );
  160.         if ( $char == "x" || $char == "X" || $char == "" )
  161.             break;
  162.  
  163.         $power = $size - $i;
  164.  
  165.         $newVal = getHexInt( $char );
  166.         $newVal = $newVal * (power( 16, $power ) );
  167.         $value += $newVal;
  168.     }
  169.  
  170.     return $value;
  171. }
  172.  
  173. proc int orInt( int $first, int $second )
  174. {
  175.     int $newVal = $first + $second;
  176.     if ( $newVal > 15 )
  177.         $newVal = 15;
  178.  
  179.     return $newVal;
  180. }
  181.  
  182. // Does a ( $first | $second ), and assumes that the strings
  183. // are truly hex strings
  184. proc string orHexString( string $first, string $second )
  185. {
  186.     float $sizeF = `size $first`;
  187.     float $sizeS = `size $second`;
  188.     int $maxSize = `max $sizeF $sizeS` - 3;
  189.     int $fIndex = $sizeF;
  190.     int $sIndex = $sizeS;
  191.     int $fInt, $sInt;
  192.  
  193.     int $newInts[];
  194.  
  195.     for ( $i = 0; $i < $maxSize; $i++ )
  196.     {
  197.         string $f = getChar( $first, $fIndex );
  198.         string $s = getChar( $second, $sIndex );
  199.  
  200.         if ( $f == "x" || $f == "X" || $f == "" )
  201.             $fInt = 0;
  202.         else
  203.             $fInt = getHexInt( $f );
  204.         if ( $s == "x" || $s == "X" || $s == "" )
  205.             $sInt = 0;
  206.         else
  207.             $sInt = getHexInt( $s );
  208.  
  209.         int $newVal = orInt( $fInt, $sInt );
  210.         $newInts[$i] = $newVal;
  211.  
  212.         $fIndex--;
  213.         $sIndex--;
  214.     }
  215.  
  216.  
  217.     string $newString = "0x";
  218.     for ( $i = $maxSize; $i >= 0; $i-- )
  219.     {
  220.         string $newChar = getHexChar( $newInts[$i] );
  221.         $newString += $newChar;
  222.     }
  223.  
  224.     return $newString;
  225. }
  226.  
  227. // Given an int, converts it to a hex string with preceeding "0x"
  228. // This function generates 4 byte (8 hex chars) strings
  229. proc string intToHexString( int $intVal )
  230. {
  231.     string $chars[];
  232.     float $value = $intVal;
  233.  
  234.     for ( $i = 0; $i < 8; $i++ )
  235.     {
  236.         float $mod = `fmod $value 16`;
  237.  
  238.         $value = $value - $mod;
  239.         $value = $value / 16;
  240.         $chars[$i] = getHexChar( $mod );
  241.     }
  242.  
  243.     string $ret = "0x";
  244.     for ( $i = 7; $i >= 0; $i-- )
  245.         $ret += $chars[$i];
  246.  
  247.     return $ret;
  248. }
  249.  
  250. // Utility func - checks to see if the given string is in the
  251. // given string array
  252. proc int stringIsInArray( string $str, string $strArray[] )
  253. {
  254.     for ( $name in $strArray )
  255.     {
  256.         if ( $str == $name )
  257.             return 1;
  258.     }
  259.  
  260.     return 0;
  261. }
  262.  
  263. // A few utility functions follow to get various data out of the
  264. // blind data template nodes.
  265.  
  266. // This func gets the id assigned to the given template node.
  267. // The node is specified by name
  268. proc int getId( string $templateNode )
  269. {
  270.     string $cmd = "getAttr " + $templateNode + ".typeId";
  271.     int $id = `eval( $cmd )`;
  272.     return $id;
  273. }
  274.  
  275. // The blindDataType nodes have bdun (blind data user name) and
  276. // bduv (blind data user value) attributes with which we can specify
  277. // some of the extra data we're tracking for editing purposes. 
  278.  
  279. // The following few are generic ones for setting and getting data and name
  280. // at a specified index.
  281. // The indices that we're using are:
  282. // 0: TypeTag (a name which is uniquely mapped to the ID ( a string's a bit easier to
  283. //               remember than an int) )
  284. // 1: AssociationType (face, vertex, object, any)
  285. // 2: Unused
  286. // 3: Free Set (whether the user can set the data with whatever value they want, or
  287. //                is restricted to the predefined presets)
  288. // 4: Data Count - how many attributes in this blind data node
  289. // 5+: The attributes. The name (bdun[index]) is the long name of the attribute, and
  290. //        the value is the data type.
  291.  
  292. proc setUserDefinedAttr( string $bdt, int $index, string $name, string $value )
  293. {
  294.     string $cmd = "setAttr " + $bdt + ".bdui[" + $index + "].bdun -type \"string\" ";
  295.     $cmd += "\"" + $name + "\"";
  296. //    print( $cmd + "\n" );
  297.     eval( $cmd );
  298.     $cmd = "setAttr " + $bdt + ".bdui[" + $index + "].bduv -type \"string\" ";
  299.     $cmd += "\"" + $value + "\"";
  300. //    print( $cmd + "\n" );
  301.     eval( $cmd );
  302. }
  303.  
  304. proc string getUserDefinedAttrName( string $bdt, int $index )
  305. {
  306.     string $cmd = "getAttr " + $bdt + ".bdui[" + $index + "].bdun";
  307.     string $name = `eval( $cmd )`;
  308.     return $name;
  309. }
  310.  
  311. proc setUserDefinedAttrName( string $bdt, int $index, string $name )
  312. {
  313.     string $cmd = "setAttr " + $bdt + ".bdui[" + $index + "].bdun";
  314.     $cmd += " -type \"string\" \"" + $name + "\"";
  315. //    print( $cmd + "\n" );
  316.     eval( $cmd );
  317. }
  318.  
  319. proc string getUserDefinedAttrVal( string $bdt, int $index )
  320. {
  321.     string $cmd = "getAttr " + $bdt + ".bdui[" + $index + "].bduv";
  322.     string $name = `eval( $cmd )`;
  323.     return $name;
  324. }
  325.  
  326. proc setUserDefinedAttrVal( string $bdt, int $index, string $val )
  327. {
  328.     string $cmd = "setAttr " + $bdt + ".bdui[" + $index + "].bduv";
  329.     $cmd += " -type \"string\" \"" + $val + "\"";
  330. //    print( $cmd + "\n" );
  331.     eval( $cmd );
  332. }
  333.  
  334. // The following are hardcoded based on the values commented above.
  335. // If you change around how you're using the bdun/bduv (user-defined values/names)
  336. // you'll need to change the indices here.
  337. proc string getTag( string $bdt )
  338. {
  339.     string $name = getUserDefinedAttrName( $bdt, 0 );
  340.     if ( $name == "typeTag" )
  341.         return getUserDefinedAttrVal( $bdt, 0 );
  342.     else
  343.         return "";
  344. }
  345.  
  346. proc setTag( string $bdt, string $tag )
  347. {
  348.     setUserDefinedAttrName( $bdt, 0, "typeTag" );
  349.     setUserDefinedAttrVal( $bdt, 0, $tag );
  350. }
  351.  
  352. proc string getAssocType( string $bdt )
  353. {
  354.     string $name = getUserDefinedAttrName( $bdt, 1 );
  355.     if ( $name == "assocType" )
  356.         return getUserDefinedAttrVal( $bdt, 1 );
  357.     else
  358.         return "";
  359. }
  360.  
  361. proc setAssocType( string $bdt, string $assocType )
  362. {
  363.     setUserDefinedAttrName( $bdt, 1, "assocType" );
  364.     setUserDefinedAttrVal( $bdt, 1, $assocType );
  365. }
  366.  
  367. proc int getFreeSet( string $bdt )
  368. {
  369.     string $name = getUserDefinedAttrName( $bdt, 3 );
  370.     if ( $name == "freeSet" )
  371.     {
  372.         $name = getUserDefinedAttrVal( $bdt, 3 );
  373.         if ( $name == "0" || $name == "" )
  374.             return 0;
  375.         else
  376.             return 1;
  377.     }
  378.     else
  379.         return 1;
  380. }
  381.  
  382. proc setFreeSet( string $bdt, int $freeSet )
  383. {
  384.     setUserDefinedAttrName( $bdt, 3, "freeSet" );
  385.     if ( $freeSet )
  386.         setUserDefinedAttrVal( $bdt, 3, "1" );
  387.     else
  388.         setUserDefinedAttrVal( $bdt, 3, "0" );
  389. }
  390.  
  391. // Data count is how many attributes there are for this template node
  392. proc int getDataCount( string $bdt )
  393. {
  394.     string $name = getUserDefinedAttrName( $bdt, 4 );
  395.     if ( $name == "dataCount" )
  396.     {
  397.         $name = getUserDefinedAttrVal( $bdt, 4 );
  398.         int $count = $name;
  399.         return $count;
  400.     }
  401.     else
  402.     {
  403.         string $dynAttrs[] = `listAttr -ud $bdt`;
  404.         return size( $dynAttrs );
  405.     }
  406. }
  407.  
  408. proc setDataCount( string $bdt, int $count )
  409. {
  410.     setUserDefinedAttrName( $bdt, 4, "dataCount" );
  411.     string $name = $count;
  412.     setUserDefinedAttrVal( $bdt, 4, $count );
  413. }
  414.  
  415. // Because we don't know how many long names (attributes)
  416. // will be in the node, we start at ($bdeNumUdAttrsUsed) and
  417. // just go up from there. There is thus an implicit order involved
  418. // in getting/setting the attrs (which could be returned in any
  419. // order if just doing a listAttr-type call)
  420. proc string getLongName( string $bdt, int $index )
  421. {
  422.     global int $bdeNumUdAttrsUsed;
  423.  
  424.     int $i = $bdeNumUdAttrsUsed + $index;
  425.     string $name = getUserDefinedAttrName( $bdt, $i );
  426.     if ( $name == "" )
  427.     {
  428.         string $dynAttrs[] = `listAttr -ud $bdt`;
  429.         if ( size( $dynAttrs ) >= $index )
  430.             return $dynAttrs[$index];
  431.         else
  432.             return "";
  433.     }
  434.     else
  435.         return $name;
  436. }
  437.  
  438. proc setLongName( string $bdt, int $index, string $attrName )
  439. {
  440.     global int $bdeNumUdAttrsUsed;
  441.  
  442.     int $i = $bdeNumUdAttrsUsed + $index;
  443.     setUserDefinedAttrName( $bdt, $i, $attrName );
  444. }
  445.  
  446. proc string getShortName( string $bdt, int $index )
  447. {
  448.     string $longName = getLongName( $bdt, $index );
  449.     if ( $longName != "" )
  450.     {
  451.         string $cmd = "listAttr -sn " + $bdt + "." + $longName;
  452.         string $shortName[] = `eval( $cmd )`;
  453.         return $shortName[0];
  454.     }
  455.     else
  456.         return "";
  457. }
  458.  
  459. // Data type can be one of:
  460. // int
  461. // double
  462. // hex (equivalent internally to int, but within the editor
  463. //      you can or and and values together, etc)
  464. // boolean
  465. // string
  466. // binary (internally equivalent to a string)
  467. proc string getDataType( string $bdt, int $index )
  468. {
  469.     global int $bdeNumUdAttrsUsed;
  470.  
  471.     int $i = $bdeNumUdAttrsUsed + $index;
  472.     string $type = getUserDefinedAttrVal( $bdt, $i );
  473.     if ( $type != "" )
  474.         return $type;
  475.     else
  476.     {
  477.         string $dynAttrs[] = `listAttr -ud $bdt`;
  478.         if ( size( $dynAttrs ) >= $index )
  479.         {
  480.             int $id = getId( $bdt );
  481.             string $cmd = "blindDataType -q -id " + $id + " -tn -ldn " + $dynAttrs[$index];
  482.             string $types[] = `eval( $cmd )`;
  483.             return $types[0];
  484.         }
  485.         else
  486.             return "";
  487.     }
  488. }
  489.  
  490. proc setDataType( string $bdt, int $index, string $dataType )
  491. {
  492.     global int $bdeNumUdAttrsUsed;
  493.  
  494.     int $i = $bdeNumUdAttrsUsed + $index;
  495.     setUserDefinedAttrVal( $bdt, $i, $dataType );
  496. }
  497.  
  498. // Note that you need the attribute name here for min val
  499. // This is a faster lookup (since we're actually checking
  500. // the attribute instead of the user-defined data)
  501. // Most of the other data is specified by index, however, and
  502. // mel won't complain if you pass an int as a string, so take
  503. // care that you use the attribute name (can do a getLongName( $bdt, $index)
  504. // to get the attr name)
  505. proc float getMinVal( string $bdt, string $attrName )
  506. {
  507.     string $cmd = "attributeQuery -r -n " + $bdt + " " + $attrName;
  508.     float $range[] = `eval( $cmd )`;
  509.     return $range[0];
  510. }
  511.  
  512. // Note that you need the attribute name here for min val
  513. // This is a faster lookup (since we're actually checking
  514. // the attribute instead of the user-defined data)
  515. // Most of the other data is specified by index, however, and
  516. // mel won't complain if you pass an int as a string, so take
  517. // care that you use the attribute name (can do a getLongName( $bdt, $index)
  518. // to get the attr name)
  519. proc float getMaxVal( string $bdt, string $attrName )
  520. {
  521.     string $cmd = "attributeQuery -r -n " + $bdt + " " + $attrName;
  522.     float $range[] = `eval( $cmd )`;
  523.     return $range[1];
  524. }
  525.  
  526. // Note that you need the attribute name here for min val
  527. // This is a faster lookup (since we're actually checking
  528. // the attribute instead of the user-defined data)
  529. // Most of the other data is specified by index, however, and
  530. // mel won't complain if you pass an int as a string, so take
  531. // care that you use the attribute name (can do a getLongName( $bdt, $index)
  532. // to get the attr name)
  533. proc int getRanged( string $bdt, string $attrName )
  534. {
  535.     string $cmd1 = "attributeQuery -re -n " + $bdt + " " + $attrName;
  536.     int $hasRange = `eval( $cmd1 )`;
  537.         return $hasRange;
  538. }
  539.  
  540. // If any of the types are hex, we return "hex".
  541. // If there are three attrs, and all three are double/floats
  542. // and all three are ranged at [0, 1], we return "asColor".
  543. // Otherwise it's normal apply mode...
  544. proc string getApplyMode( string $bdt )
  545. {
  546.     string $dataType[];
  547.     int $dataCount = getDataCount( $bdt );
  548.     for ( $i = 0; $i < $dataCount; $i++ )
  549.     {
  550.         $dataType[$i] = getDataType( $bdt, $i );
  551.         if ( $dataType[$i] == "hex" )
  552.             return "hex";
  553.     }
  554.     if ( $dataCount == 3 )
  555.     {
  556.         if ( ($dataType[0] == "double" || $dataType[0] == "float" ) && 
  557.              ($dataType[1] == "double" || $dataType[1] == "float" ) && 
  558.              ($dataType[2] == "double" || $dataType[2] == "float" ) )
  559.         {
  560.             float $min[], $max[];
  561.             for ( $i = 0; $i < $dataCount; $i++ )
  562.             {
  563.                 $name = getLongName( $bdt, $i );
  564.                 $min[$i] = getMinVal( $bdt, $name );
  565.                 $max[$i] = getMaxVal( $bdt, $name );
  566.                 if ( $min[0] == 0 && $min[1] == 0 && $min[2] == 0 &&
  567.                      $max[0] == 1 && $max[1] == 1 && $max[2] == 1 )
  568.                      return "asColor";
  569.             }
  570.         }
  571.     }
  572.  
  573.     return "normal";
  574. }
  575.  
  576. // $presetName is an identifier for this preset (which will appear at 
  577. // index $index)
  578. // $attrName[] should have the names of the attributes in the order
  579. // they appear in the bdun/bduv values, and 
  580. // $presetVal[] should have the corresponding values for this preset
  581. proc setPreset( string $bdt, string $presetName, 
  582.                 string $attrName[], string $presetVal[], int $index )
  583. {
  584.     string $baseCmd = "setAttr " + $bdt + ".bdps[" + $index + "]";
  585.     string $cmd = $baseCmd + ".bdpn -type \"string\" ";
  586.     $cmd += "\"" + $presetName + "\"";
  587. //    print( $cmd + "\n" );
  588.     eval( $cmd );    
  589.     for ( $i = 0; $i < size( $presetVal ); $i++ )
  590.     {
  591.         string $nextCmd = $baseCmd + ".bdpe[" + $i + "]";
  592.         $cmd = $nextCmd + ".bdpa -type \"string\" ";
  593.         $cmd += "\"" + $attrName[$i] + "\"";
  594. //        print( $cmd + "\n" );
  595.         eval( $cmd );
  596.         $cmd = $nextCmd + ".bdpv -type \"string\" ";
  597.         $cmd += "\"" + $presetVal[$i] + "\"";
  598. //        print( $cmd + "\n" );
  599.         eval( $cmd );
  600.     }
  601. }
  602.  
  603. // How many presets there are in the given template node (passed by name of node)
  604. proc int getPresetCount( string $bdt )
  605. {
  606.     string $cmd = "attributeQuery -ex -n " + $bdt + " bdps";
  607.     if ( `eval( $cmd )` )
  608.     {
  609.         $cmd = "getAttr -size " + $bdt + ".bdps";
  610.         int $num = `eval( $cmd )`;
  611.         return $num;
  612.     }
  613.     else
  614.         return 0;
  615. }
  616.  
  617. // Presets are stored according to indices...
  618. // Because each preset is a complete set of data,
  619. // the order of the presets doesn't matter, and each
  620. // preset value is indexed by attribute name, so that
  621. // order is not important either.
  622. proc string getPresetName( string $bdt, int $index )
  623. {
  624.     string $cmd = "getAttr " + $bdt + ".bdps[" + $index + "]";
  625.     $cmd += ".bdpn";
  626.     string $name = `eval( $cmd )`;
  627.     return $name;
  628. }
  629.  
  630. // This is the number of preset values assigned for the given
  631. // preset (at index $index). This should match the number of 
  632. // attributes for this blindDataTemplate node (getDataCount( $bdt ) ).
  633. proc int getNumPresetVals( string $bdt, int $index )
  634. {
  635.     string $cmd = 
  636.     $cmd = "getAttr -size " + $bdt + ".bdps[" + $index + "].bdpe";
  637.     int $num = `eval( $cmd )`;
  638.     return $num;
  639. }
  640.  
  641. // Get the presetVal corresponding to the given attribute 
  642. // for the preset at the given index 
  643. proc string getPresetVal( string $bdt, int $index, string $attrName )
  644. {
  645.     string $cmd;
  646.     string $baseCmd = "getAttr " + $bdt + ".bdps[" + $index + "].bdpe";
  647.     int $numVals = getNumPresetVals( $bdt, $index );
  648.     for ( $i = 0; $i < $numVals; $i++ )
  649.     {
  650.         $cmd = $baseCmd + "[" + $i + "].bdpa";
  651.         string $name = `eval( $cmd )`;
  652.         if ( $name == $attrName )
  653.         {
  654.             $cmd = $baseCmd + "[" + $i + "].bdpv";
  655.             $name = `eval( $cmd )`;
  656.             return $name;
  657.         }
  658.     }
  659.  
  660.     return "";
  661. }
  662.  
  663. // The returned stringArray contains an entry (presetVal) for each attribute
  664. // in the node.
  665. proc string[] getPresetVals( string $bdt, int $index )
  666. {
  667.     string $ret[];
  668.     int $presetCount = getPresetCount( $bdt );
  669.     if ( $index > $presetCount )
  670.         return $ret;
  671.     int $dataCount = getDataCount( $bdt );
  672.     for ( $i = 0; $i < $dataCount; $i++ )
  673.     {
  674.         $attr = getLongName( $bdt, $i );
  675.         $ret[$i] = getPresetVal( $bdt, $index, $attr );
  676.     }
  677.  
  678.     return $ret;
  679. }
  680.  
  681. // Given a typeId, this func returns the name of the 
  682. // blind data template node with that typeId.
  683. // If none matches, the empty string is returned.
  684. proc string getTemplateNameFromId( int $id )
  685. {
  686.     // Bug 150384 check exact type so we don't get subd blind data
  687.     string $blindDataTemplates[] = `ls -exactType blindDataTemplate`;
  688.     string $cmd;
  689.  
  690.     for ( $bdt in $blindDataTemplates )
  691.     {
  692.         $cmd = "getAttr " + $bdt + ".typeId";
  693.         int $thisId = `eval $cmd`;
  694.         if ( $thisId == $id )
  695.         {
  696.             return $bdt;
  697.         }
  698.     }
  699.  
  700.     return "";
  701. }
  702.  
  703. // Similarly, this function returns the name of the blind
  704. // data template node given the user-defined "tag" for that node.
  705. // Again, an empty string is returned if none matches.
  706. proc string getTemplateNameFromTag( string $tag )
  707. {
  708.     // Bug 150384 check exact type so we don't get subd blind data
  709.     string $blindDataTemplates[] = `ls -exactType blindDataTemplate`;
  710.  
  711.     for ( $bdt in $blindDataTemplates )
  712.     {
  713.         $name = getTag( $bdt );
  714.         if ( $tag == $name )
  715.             return $bdt;
  716.     }
  717.  
  718.     return "";
  719. }
  720.  
  721. // Query/color
  722.  
  723. // What follows is a bunch of utility functions for the query/color tab
  724. // (hence the Qc in the function name).
  725. // Much of this Qc code will be a little difficult to decipher because
  726. // of the necessity to use the full path name ot the controls.
  727. // The reason the full pathnames are required is that the
  728. // query/color rows can constantly change. Hence we track the name of the 
  729. // layout (a columnLayout) and get all of the controls relative to this
  730. // control. Typically, the layout is the $parent argument to these qc functions.
  731.  
  732. // Sets the value of the specified value field. This value field is a text
  733. // field regardless of the data type.
  734. // If the index is > 0, the data we're looking at lives in the 'multiList' child.
  735. // This multilist has a dataLayout child, which has a child rowLayout#, where
  736. // # is the index of the data.
  737. proc setQcValue( string $parent, int $index, string $val )
  738. {
  739.     if ( $index == 0 )
  740.         $control = $parent + "|mainLine|value";
  741.     else
  742.         $control = $parent + "|multiList|dataLayout|rowLayout" + $index + "|value";
  743.  
  744.     if ( `textField -q -ex $control` )
  745.         textField -e -tx $val $control;
  746. }
  747.  
  748. // Gets the text value at the specified $index.
  749. proc string getQcValue( string $parent, int $index )
  750. {
  751.     string $control;
  752.  
  753.     if ( $index == 0 )
  754.         $control = $parent + "|mainLine|value";
  755.     else
  756.         $control = $parent + "|multiList|dataLayout|rowLayout" + $index + "|value";
  757.  
  758.     if ( `textField -q -ex $control` )
  759.         return `textField -q -tx $control`;
  760.     else
  761.         return "";
  762. }
  763.  
  764. // Returns the name of the blindDataTemplate node for the specified
  765. // query/color row.
  766. // The name of the type box can be the 'Tag' of the bdt, for which
  767. // the first getTemplateNameFromTag will return the right value.
  768. // The type box can also have the id# of the blind data template node,
  769. // however; in this case, we do a getTemplateNameFromId and hope this
  770. // is the right one. (If it's not, empty string will be returned)
  771. proc string getQcSelectedBdt( string $parent )
  772. {
  773.     string $control = $parent + "|mainLine|type";
  774.     string $type = `textField -q -tx $control`;
  775.     string $name = getTemplateNameFromTag( $type );
  776.     if ( $name == "" )
  777.     {
  778.         if ( $type != "" )
  779.         {
  780.             int $id = $type;
  781.             $name = getTemplateNameFromId( $id );
  782.         }
  783.     }
  784.     return $name;
  785. }
  786.  
  787. proc int getNumQcValues( string $parent )
  788. {
  789.     int $numVals = 1;
  790.     string $layout = $parent + "|multiList|dataLayout";
  791.     if ( `columnLayout -q -ex $layout` )
  792.     {
  793.         string $children[] = `columnLayout -q -ca $layout`;
  794.         $numVals += size( $children );
  795.     }
  796.     return $numVals;
  797. }
  798.  
  799. // This enable specifies whether user wants to use this
  800. // row for qc operation.
  801. proc int getQcEnable( string $parent )
  802. {
  803.     string $control = $parent + "|mainLine|enable";
  804.     if ( `checkBox -q -ex $control` )
  805.         return `checkBox -q -v $control`;
  806.     else
  807.         return 0;
  808. }
  809.  
  810. proc setQcEnable( string $parent, int $val )
  811. {
  812.     string $control = $parent + "|mainLine|enable";
  813.     if ( `checkBox -q -ex $control` )
  814.         checkBox -e -en true -v $val $control;
  815. }
  816.  
  817. // The way it was designed, this type value should be set
  818. // with the popup menu for the box. Since it is just a text
  819. // box, however, the user can also type in a value.
  820. // Acceptable values are the 'tag' for the blind data template,
  821. // or the id. Either of these should result in the correct
  822. // blind data template being accessed. (see getQcSelectedBdt() )
  823. proc string getQcType( string $parent )
  824. {
  825.     string $control = $parent + "|mainLine|type";
  826.     string $type = "";
  827.     if ( `textField -q -ex $control` )
  828.         $type = `textField -q -tx $control`;
  829.     return $type;
  830. }
  831.  
  832. // The 'MainColor' is the color of the canvas you see on the main line
  833. // of the qc row. If the value chooser is set to be continuous/grayscale
  834. // data or asColor data, this canvas is blacked out (and should be disabled) and 
  835. // the proper color saved in the 'saveColor' canvas. (see getQcSaveColor()).
  836. proc setQcMainColor( string $parent, float $color[] )
  837. {
  838.     string $control = $parent + "|mainLine|canvas";
  839.     if ( `canvas -q -ex $control` )
  840.         canvas -edit -rgbValue $color[0] $color[1] $color[2] $control;
  841. }
  842.  
  843. proc float[] getQcMainColor( string $parent )
  844. {
  845.     float $color[] = { 0, 0, 0 };
  846.     string $control = $parent + "|mainLine|canvas";
  847.     if ( `canvas -q -ex $control` )
  848.         $color = `canvas -query -rgbValue $control`;
  849.  
  850.     return $color;
  851. }
  852.  
  853. // The save color is the color of the row as it was before it was blacked out
  854. // (because the user selected continuous or asColor, and the grayscale colors 
  855. // appeared). We need to save this color so if they go back to a discrete color
  856. // choice the one it was set to before is restored properly. 
  857. // This canvas is not visible.
  858. proc setQcSaveColor( string $parent, float $color[] )
  859. {
  860.     string $control = $parent + "|valueLayout|valueForm|valueTypeLayout|saveColor";
  861.     if ( `canvas -q -ex $control` )
  862.         canvas -edit -rgbValue $color[0] $color[1] $color[2] $control;
  863. }
  864.  
  865. proc float[] getQcSaveColor( string $parent )
  866. {
  867.     float $color[] = { 0, 0, 0 };
  868.     string $control = $parent + "|valueLayout|valueForm|valueTypeLayout|saveColor";
  869.     if ( `canvas -q -ex $control` )
  870.         $color = `canvas -query -rgbValue $control`;
  871.  
  872.     return $color;
  873. }
  874.  
  875. // This func is used when opening up the blind data editor. 
  876. // It serves to simplify restoring userPrefs when opening
  877. // up the blindDataEditor.
  878. proc setQcTypeAndColors( string $parent, string $type, float $mainColor[], float $saveColor[] )
  879. {
  880.     string $control = $parent + "|mainLine|type";
  881.     if ( `textField -q -ex $control` )
  882.     {
  883.         textField -e -tx $type $control;
  884.         bdeQcChangeType( $parent );
  885.         setQcMainColor( $parent, $mainColor );
  886.         setQcSaveColor( $parent, $saveColor );
  887.     }
  888. }
  889.  
  890. // Value enable is a check box specifying whether or not
  891. // the 'values' should be used (if unchecked, the user wants
  892. // to query/color the data based only on whether the type is
  893. // present or not. Otherwise, there are more options for specifying
  894. // how to consider the actual value of the data (i.e. a specific value
  895. // or range, asColor, etc.)
  896. proc int getQcValueEnable( string $parent )
  897. {
  898.     string $control = $parent + "|mainLine|valueEnable";
  899.     if ( `checkBox -q -ex $control` )
  900.         return `checkBox -q -v $control`;
  901.     else
  902.         return 0;
  903. }
  904.  
  905. proc setQcValueEnable( string $parent, int $enable )
  906. {
  907.     string $control = $parent + "|mainLine|valueEnable";
  908.     if ( `checkBox -q -ex $control` )
  909.     {
  910.         checkBox -e -en true -v $enable $control;
  911.         bdeQcChangeValueEnable( $parent );
  912.     }
  913. }
  914.  
  915. // These next two functions are just to facilitate saving user data before
  916. // the panel is torn off or deleted
  917. proc string[] getQcValues( string $parent )
  918. {
  919.     string $values[];
  920.     int $index = 0;
  921.     int $numVals = getNumQcValues( $parent );
  922.     for ( $i = 0; $i < $numVals; $i++ )
  923.     {
  924.         $values[$index++] = getQcValue( $parent, $i );
  925.     }
  926.  
  927.     return $values;
  928. }
  929.  
  930. // Select type appears in the 'valueLayout', a frame that opens when the user
  931. // enables the valueEnable checkbox. Select type can be one of:
  932. // $bdeDiscreteValName = "discrete value";
  933. // $bdeDiscreteRangeName = "discrete range";
  934. // $bdeHexValName = "hex";
  935. // $bdeContinuousName = "continuous";
  936. // $bdeAsColorName = "as color";
  937. proc string getQcSelectType( string $parent )
  938. {
  939.     string $control = $parent + "|valueLayout|valueForm|valueTypeLayout|valueType";
  940.     if ( `optionMenu -q -ex $control` )
  941.         return `optionMenu -q -v $control`;
  942.     else
  943.         return "";
  944. }
  945.  
  946. // Open or close the 'valueLayout' frame
  947. proc toggleCollapseQcSelectType( string $parent, int $open )
  948. {
  949.     string $control = $parent + "|valueLayout";
  950.     if ( `frameLayout -q -ex $control` )
  951.     {
  952.         if ( $open )
  953.             frameLayout -e -cl false $control;
  954.         else
  955.             frameLayout -e -cl true $control;
  956.     }
  957. }
  958.  
  959. proc setQcSelectType( string $parent, string $val )
  960. {
  961.     string $control = $parent + "|valueLayout|valueForm|valueTypeLayout|valueType";
  962.     if ( `optionMenu -q -ex $control` )
  963.     {
  964.         optionMenu -e -v $val $control;
  965.         bdeQcOpenValueTab( $parent, 0 );
  966.     }
  967. }
  968.  
  969. // some funcs to facilitate storing/restoring user values
  970. proc string getQcFilledRow( int $index )
  971. {
  972.     int $numRows = 0;
  973.     global string $bdeQueryColorLayout;
  974.     if ( `columnLayout -q -ex $bdeQueryColorLayout` )
  975.     {
  976.         string $children[] = `columnLayout -q -ca $bdeQueryColorLayout`;
  977.         for ( $child in $children )
  978.         {
  979.             $layout = $bdeQueryColorLayout + "|" + $child;
  980.             $type = getQcType( $layout );
  981.             if ( $type != "" )
  982.             {
  983.                 if ( $numRows == $index )
  984.                     return $layout;
  985.                 $numRows++;
  986.             }
  987.         }
  988.     }
  989.     return "";
  990. }
  991.  
  992. proc int getQcNumFilledRows()
  993. {
  994.     int $numRows = 0;
  995.     global string $bdeQueryColorLayout;
  996.     if ( `columnLayout -q -ex $bdeQueryColorLayout` )
  997.     {
  998.         string $children[] = `columnLayout -q -ca $bdeQueryColorLayout`;
  999.         for ( $child in $children )
  1000.         {
  1001.             $layout = $bdeQueryColorLayout + "|" + $child;
  1002.             $type = getQcType( $layout );
  1003.             if ( $type != "" )
  1004.                 $numRows++;
  1005.         }
  1006.     }
  1007.  
  1008.     return $numRows;
  1009. }
  1010.  
  1011. // $bdeQueryColorLayout is the parent qc layout.
  1012. // The children are all of the current query/color rows.
  1013. proc int getQcNumRows()
  1014. {
  1015.     global string $bdeQueryColorLayout;
  1016.     int $num = 0;
  1017.  
  1018.     if ( `columnLayout -q -ex $bdeQueryColorLayout` )
  1019.     {
  1020.         string $children[] = `columnLayout -q -ca $bdeQueryColorLayout`;
  1021.         $num = size( $children );
  1022.     }
  1023.  
  1024.     return $num;
  1025. }
  1026.  
  1027. // Checks whether this id is defined for any blindDataTemplate nodes in the scene
  1028. proc int idDefined( int $id )
  1029. {
  1030.     // Bug 150384 check exact type so we don't get subd blind data
  1031.     string $blindDataTemplates[] = `ls -exactType blindDataTemplate`;
  1032.  
  1033.     for ( $bdt in $blindDataTemplates )
  1034.     {
  1035.         string $cmd = "getAttr " + $bdt + ".typeId";
  1036.         if ( `eval( $cmd )` == $id )
  1037.             return 1;
  1038.     }
  1039.  
  1040.     return 0;
  1041. }
  1042.  
  1043. // Checks whether this tag is defined for any bdt's in the scene
  1044. proc int tagDefined( string $tag )
  1045. {
  1046.     // Bug 150384 check exact type so we don't get subd blind data
  1047.     string $blindDataTemplates[] = `ls -exactType blindDataTemplate`;
  1048.  
  1049.     for ( $bdt in $blindDataTemplates )
  1050.     {
  1051.         if ( getTag( $bdt ) == $tag )
  1052.             return 1;
  1053.     }
  1054.  
  1055.     return 0;
  1056. }
  1057.  
  1058. // For internal use (creating attr's if using them (at the object level)
  1059. // instead of (component) blind data
  1060. proc string getGenericDataType( string $type )
  1061. {
  1062.     if ( $type == "string" || $type == "binary" )
  1063.         return "string";
  1064.     if ( $type == "double" || $type == "float" )
  1065.         return "double";
  1066.     if ( $type == "int" || $type == "hex" )
  1067.         return "long";
  1068.     if ( $type == "boolean" )
  1069.         return "bool";
  1070. }
  1071.  
  1072. // Proper flag for querying poly blind data
  1073. proc string getDataTypeFlag( string $type )
  1074. {
  1075.     if ( $type == "int" || $type == "hex" )
  1076.         return "-intData";
  1077.     else if ( $type == "float" || $type == "double" )
  1078.         return "-doubleData";
  1079.     else if ( $type == "boolean" )
  1080.         return "-booleanData";
  1081.     else if ( $type == "string" )
  1082.         return "-stringData";
  1083.     else if ( $type == "binary" )
  1084.         return "-binaryData";
  1085.     else {
  1086.         return "-invalidData";
  1087. }
  1088. }
  1089.  
  1090. // There are a couple of lists this could come from.
  1091. // bdeTemplateList (Type editor tab) and bdeTypeList (apply tab)
  1092. // This returns which one is selected. If the selected one has not
  1093. // tag, an empty string is returned (in this case, use getCurrentId
  1094. // and the id will be returned)
  1095. proc string getCurrentTag( string $list )
  1096. {
  1097.     string $tags[] = `textScrollList -q -si $list`;
  1098.  
  1099.     if ( "" == $tags[0] )
  1100.         return "";
  1101.     else
  1102.     {
  1103.         string $buffer[];
  1104.         int $numTokens = tokenize( $tags[0], $buffer );
  1105.         if ( $numTokens == 2 )
  1106.             return $buffer[0];
  1107.         else
  1108.             return "";
  1109.     }
  1110. }
  1111.  
  1112. // This returns the id of the selected template in the given list
  1113. // possible lists are bdeTemplateList (type editor tab) and
  1114. // bdeTypeList (apply tab)
  1115. proc int getCurrentId( string $list )
  1116. {
  1117.     string $tags[] = `textScrollList -q -si $list`;
  1118.  
  1119.     if ( "" == $tags[0] )
  1120.         return -1;
  1121.     else
  1122.     {
  1123.         string $buffer[];
  1124.         int $numTokens = tokenize( $tags[0], $buffer );
  1125.         if ( $numTokens == 2 )
  1126.         {
  1127.             int $l = size( $buffer[1] );
  1128.             string $id = `substring $buffer[1] 2 ($l-1)`;
  1129.             return $id;
  1130.         }
  1131.         else if ( $numTokens == 1 )
  1132.         {
  1133.             int $id = $buffer[0];
  1134.             return $id;
  1135.         }
  1136.         else
  1137.             return -1;
  1138.     }
  1139. }
  1140.  
  1141. // This returns the id of the selected template in the TypeEditor tab.
  1142. // if none is selected, or the list doesn't exist
  1143. // -1 is returned.
  1144. proc int getTemplateTagId()
  1145. {
  1146.     int $i, $id;
  1147.     string $blindDataTags[];
  1148.     string $blindDataIds[];
  1149.  
  1150.     string $tag = getCurrentTag( "bdeTemplateList" );
  1151.     if ( "" == $tag )
  1152.         return getCurrentId( "bdeTemplateList" );
  1153.  
  1154.     // Bug 150384 check exact type so we don't get subd blind data
  1155.     string $nodes[] = `ls -exactType blindDataTemplate`;
  1156.     for ( $i = 0; $i < size( $nodes ); $i++ )
  1157.     {
  1158.         string $thisTag = getTag( $nodes[$i] );
  1159.         if ( $thisTag == $tag )
  1160.         {
  1161.             $id = getId( $nodes[$i] );
  1162.             return $id;
  1163.         }
  1164.     }
  1165.  
  1166.     return -1;
  1167. }
  1168.  
  1169. // This returns the child of the bdeSingleApplyLayout
  1170. // (a tabLayout with invisible tabs) corresponding to the
  1171. // given id.
  1172. // The apply tab's only child is this bdeSingleApplyLayout,
  1173. // and each of the id's gets it's own layout, which will be 
  1174. // a child of this bdeSingleApplyLayout.
  1175. // This means that we can switch tabs without having to rebuild
  1176. // the layout, which is faster after the initial build, and 
  1177. // allows us to keep the user data as he/she has set it without
  1178. // saving and restoring it.
  1179. proc string getApplyTab( int $id )
  1180. {
  1181.     string $thisTab = "bdeApply" + $id;
  1182.     string $bdt = getTemplateNameFromId( $id );
  1183.     if ( $bdt == "" )
  1184.         return "";
  1185.  
  1186.     string $thisTabLabel = getTag( $bdt );
  1187.     if ( $thisTabLabel == "" )
  1188.         $thisTabLabel = "" + $id;    
  1189.  
  1190.     string $children[] = `tabLayout -q -ca bdeSingleApplyLayout`;
  1191.  
  1192.     for ( $child in $children )
  1193.     {
  1194.         if ( $child == $thisTab )
  1195.             return $child;
  1196.     }
  1197.  
  1198.     return "";
  1199. }
  1200.  
  1201. // Returns the name of the template of the currently selected
  1202. // item in the apply tab.
  1203. proc string getCurrentApplyTemplate()
  1204. {
  1205.     string $tag = getCurrentTag( "bdeTypeList" );
  1206.     if ( "" == $tag )
  1207.     {
  1208.         int $id = getCurrentId( "bdeTypeList" );
  1209.         return getTemplateNameFromId( $id );
  1210.     }
  1211.     else
  1212.         return getTemplateNameFromTag( $tag );
  1213. }
  1214.  
  1215. // This also returns the name of the template of the currently selected
  1216. // item in the apply tab (there needn't be two of them, but it's too
  1217. // late to change it)
  1218. proc string getSelectedApplyBdt()
  1219. {
  1220.     string $parent = "bdeSingleApplyLayout";    
  1221.     // We apply the data set at the selected tab
  1222.     string $tab = `tabLayout -q -st $parent`;
  1223.     if ( $tab == "" )
  1224.         return "";
  1225.  
  1226.     // $tab looks like bdeApply1200 or something
  1227.     int $length = `size( $tab )`;
  1228.     if ( $length < 9 )
  1229.         return "";
  1230.  
  1231.     string $idString = `substring $tab 9 $length`;
  1232.     int $id = $idString;
  1233.     return getTemplateNameFromId( $id );
  1234. }
  1235.  
  1236. // This func is used only to restore the state to what
  1237. // the user had set before a tear-off or close of the panel
  1238. proc int setSelectedApply( int $desiredId )
  1239. {
  1240.     string $items[] = `textScrollList -q -ai bdeTypeList`;
  1241.  
  1242.     int $numItems = size( $items );
  1243.     if ( $numItems == 0 )
  1244.         return 0;
  1245.     for ( $i = 0; $i < $numItems; $i++ )
  1246.     {
  1247.         string $buffer[];
  1248.         int $numTokens = tokenize( $items[$i], $buffer );
  1249.         if ( $numTokens == 2 )
  1250.         {
  1251.             int $l = size( $buffer[1] );
  1252.             string $id = `substring $buffer[1] 2 ($l-1)`;
  1253.             if ( $id == $desiredId )
  1254.             {
  1255.                 textScrollList -e -sii ($i+1) bdeTypeList;
  1256.                 return 1;
  1257.             }
  1258.         }
  1259.         else if ( $numTokens == 1 )
  1260.         {
  1261.             int $id = $buffer[0];
  1262.             if ( $id == $desiredId )
  1263.             {
  1264.                 textScrollList -e -sii ($i+1) bdeTypeList;
  1265.                 return 1;
  1266.             }
  1267.         }
  1268.     }
  1269.     return 0;
  1270. }
  1271.  
  1272. // This function is used for the apply tab.
  1273. // It sets the values in the apply tab for the given template
  1274. // to the given string array values.
  1275. // It is assumed that there are at least as many values in the string
  1276. // array as there are data fields (getDataCount()).
  1277. // If the tab for the given template does not exist, it is created
  1278. // (through bdeRebuildApplyTab( $id )).
  1279. proc bdeSetControl( string $bdt, string $newVals[] )
  1280. {
  1281.     if ( $bdt == "" )
  1282.         return;
  1283.  
  1284.     int $dataCount = getDataCount( $bdt );
  1285.     int $id = getId( $bdt );
  1286.  
  1287.     if ( getApplyTab( $id ) == "" )
  1288.     {
  1289.         string $tab = bdeRebuildApplyTab( $id );
  1290.         if ( $tab == "" )
  1291.             return;
  1292.     }
  1293.  
  1294.     for ( $i = 0; $i < $dataCount; $i++ )
  1295.     {
  1296.         string $controlName = "bdeDataValue" + $id + "_" + $i;
  1297.         string $dataType = getDataType( $bdt, $i );
  1298.         string $dataName = getLongName( $bdt, $i );
  1299.         int $ranged = getRanged( $bdt, $dataName );
  1300.  
  1301.         if ( $dataType == "string" || $dataType == "binary" )
  1302.         {
  1303.             textField -e -tx $newVals[$i] $controlName;
  1304.         }
  1305.         else if ( $dataType == "float" || $dataType == "double" )
  1306.         {            
  1307.             float $value;
  1308.             if ( $newVals[$i] == "" )
  1309.                 $value = 0;
  1310.             else
  1311.                 $value = $newVals[$i];
  1312.             if ( $ranged )
  1313.                 floatSliderGrp -e -v $value $controlName;
  1314.             else
  1315.                 floatField -e -v $value $controlName;
  1316.         }
  1317.         else if ( $dataType == "int" )
  1318.         {
  1319.             int $value;
  1320.             if ( $newVals[$i] == "" )
  1321.                 $value = 0;
  1322.             else
  1323.                 $value = $newVals[$i];
  1324.             if ( $ranged )
  1325.                 intSliderGrp -e -v $value $controlName;
  1326.             else
  1327.                 intField -e -v $value $controlName;
  1328.         }
  1329.         else if ( $dataType == "hex" )
  1330.         {
  1331.             textField -e -tx $newVals[$i] $controlName;
  1332.         }
  1333.         else if ( $dataType == "boolean" )
  1334.         {
  1335.             if ( $newVals[$i] == "1" || $newVals[$i] == "true" || $newVals[$i] == "TRUE" )
  1336.                 radioButtonGrp -e -sl 2 $controlName;
  1337.             else
  1338.                 radioButtonGrp -e -sl 1 $controlName;
  1339.         }
  1340.     }
  1341.  
  1342.     // This canvas exists if the data looks like a color
  1343.     // (i.e. three doubles [0,1].)
  1344.     // We change the canvas to reflect the new data values
  1345.     $control = "bdeColorDataCanvas" + $id;
  1346.     if ( `canvas -q -ex $control` )
  1347.     {
  1348.         float $col[];
  1349.         for ( $i = 0; $i < 3; $i++ )
  1350.         {
  1351.             $controlName = "bdeDataValue" + $id + "_" + $i;
  1352.             $col[$i] = `floatSliderGrp -q -v $controlName`;
  1353.         }
  1354.  
  1355.         canvas -edit -rgbValue $col[0] $col[1] $col[2] $control;
  1356.     }
  1357. }
  1358.  
  1359. global proc buildBlindDataEditorContextHelpItems(
  1360.     string $nameRoot, string $menuParent)
  1361. //
  1362. //  Description:
  1363. //        Build context sensitive menu items
  1364. //        
  1365. //  Input Arguments:
  1366. //        $nameRoot - name to use as the root of all item names
  1367. //        $menuParent - the name of the parent of this menu
  1368. //
  1369. //  Return Value:
  1370. //      None
  1371. //
  1372. {
  1373.     menuItem -label "Help on Blind Data Editor..."
  1374.         -enableCommandRepeat false
  1375.         -command "showHelp BlindDataEditor";
  1376. }
  1377.  
  1378. // This indicates the user has changed the value of one
  1379. // of the fields. This typically happens when there is a
  1380. // manual change of one of the fields (although it can also
  1381. // be called when the user uses the canvas to do asColor data)
  1382. global proc bdeChangedValue( int $id )
  1383. {
  1384.     string $controlName;
  1385.     string $bdt = getTemplateNameFromId( $id );
  1386.     if ( $bdt == "" )
  1387.         return;
  1388.  
  1389.     string $applyMode = getApplyMode( $bdt );
  1390.     int $presetCount = getPresetCount( $bdt );
  1391.  
  1392.     // Turn off the preset checkboxes/radiobuttons
  1393.     if ( $applyMode == "hex" )
  1394.     {
  1395.         for ( $i = 0; $i < $presetCount; $i++ )
  1396.         {
  1397.             $controlName = "bdeIndicator" + $id + "_" + $i;
  1398.             checkBox -e -v 0 $controlName;
  1399.         }
  1400.     }
  1401.     else
  1402.     {
  1403.         // bdeNoIndicator is an invisible radioButton.
  1404.         // If we turn it on, all the visible ones turn off
  1405.         // (which is what we want here)
  1406.         $controlName = "bdeNoIndicator" + $id;
  1407.         radioButton -e -sl $controlName;
  1408.     }
  1409.  
  1410.     // If we're looking at color data, we change the canvas to reflect
  1411.     // the new data (even though this func may have been called as a 
  1412.     // result of this change). Doing so here won't recall this function
  1413.     // (for a recursive loop), so it doesn't matter if this happened
  1414.     // (and we'll just be changing the color to what it was already)
  1415.     $control = "bdeColorDataCanvas" + $id;
  1416.     if ( `canvas -q -ex $control` )
  1417.     {
  1418.         float $col[];
  1419.         for ( $i = 0; $i < 3; $i++ )
  1420.         {
  1421.             $controlName = "bdeDataValue" + $id + "_" + $i;
  1422.             $col[$i] = `floatSliderGrp -q -v $controlName`;
  1423.         }
  1424.  
  1425.         canvas -edit -rgbValue $col[0] $col[1] $col[2] $control;
  1426.     }
  1427. }
  1428.  
  1429. // This function is used for splitting up a selection string
  1430. // (which looks like pPlane1.f[3]
  1431. // Return string array has 3 strings:
  1432. // [0]: pPlane1
  1433. // [1]: f
  1434. // [2]: 3
  1435. // Note that multiple selections are ignored (i.e. pPlane1.f[3:10] returns
  1436. // the same string array as pPlane1.f[3]).
  1437. proc string[] getSelectionComp( string $sel )
  1438. {    
  1439.     string $rest = "";
  1440.     string $obj = $sel;
  1441.     int $length = size( $sel );
  1442.     for ( $i = 1; $i <= $length; $i++ )
  1443.     {
  1444.         if ( getChar( $sel, $i ) == "." )
  1445.         {
  1446.             $obj = `substring $sel 1 ($i-1)`;
  1447.             $rest = `substring $sel ($i+1) $length`;
  1448.             break;
  1449.         }
  1450.     }
  1451.  
  1452.     string $comp = "";
  1453.     int $length = size( $rest );
  1454.     for ( $i = 1; $i <= $length; $i++ )
  1455.     {
  1456.         if ( getChar( $rest, $i ) == "[" )
  1457.         {
  1458.             $comp = `substring $rest 1 ($i-1)`;
  1459.             $rest = `substring $rest ($i+1) $length`;
  1460.             break;
  1461.         }
  1462.     }
  1463.  
  1464.     string $index = "";
  1465.     int $length = size( $rest );
  1466.     for ( $i = 1; $i <= $length; $i++ )
  1467.     {
  1468.         if ( getChar( $rest, $i ) == ":" )
  1469.         {
  1470.             $index = `substring $rest 1 ($i-1)`;
  1471.             break;
  1472.         }
  1473.         if ( getChar( $rest, $i ) == "]" )
  1474.         {
  1475.             $index = `substring $rest 1 ($i-1)`;
  1476.             break;
  1477.         }
  1478.     }
  1479.     
  1480.     string $array[];
  1481.     $array[0] = $obj;
  1482.     $array[1] = $comp;
  1483.     $array[2] = $index;
  1484.     return $array;
  1485. }
  1486.  
  1487. // Color functions:
  1488.  
  1489. // This function, given an absolute canvas control, 
  1490. // pops up the color editor and sets the canvas to the
  1491. // new color if OK'd
  1492. global proc int bdeChangeNamedCanvas( string $canvasName )
  1493. {
  1494.     float $oldColor[], $newColor[];
  1495.     string $buf[], $colStr;
  1496.  
  1497.     $oldColor = `canvas -query -rgbValue $canvasName`;
  1498.  
  1499.     $colStr = `colorEditor -rgb $oldColor[0] $oldColor[1] $oldColor[2]`;
  1500.  
  1501.     $numToks = tokenize( $colStr, $buf );
  1502.  
  1503.     if ( $buf[3] == 1 )
  1504.     {
  1505.         $newColor[0] = $buf[0];
  1506.         $newColor[1] = $buf[1];
  1507.         $newColor[2] = $buf[2];
  1508.         canvas -edit -rgbValue $newColor[0] $newColor[1] $newColor[2] $canvasName;
  1509.         return 1;
  1510.     }    
  1511.     else
  1512.         return 0;
  1513. }
  1514.  
  1515. // This function works similarly to the namedCanvas
  1516. // function, except that it takes an argument specifying
  1517. // which query/color row (columnLayout) the user wants to change
  1518. // the color for.
  1519. global proc bdeChangeCanvas( string $parent )
  1520. {    
  1521.     float $oldColor[], $newColor[];
  1522.     string $buf[], $colStr;
  1523.  
  1524.     string $canvasName = $parent + "|mainLine|canvas";
  1525.  
  1526.     $oldColor = `canvas -query -rgbValue $canvasName`;
  1527.  
  1528.     $colStr = `colorEditor -rgb $oldColor[0] $oldColor[1] $oldColor[2]`;
  1529.  
  1530.     $numToks = tokenize( $colStr, $buf );
  1531.  
  1532.     if ( $buf[3] == 1 )
  1533.     {
  1534.         $newColor[0] = $buf[0];
  1535.         $newColor[1] = $buf[1];
  1536.         $newColor[2] = $buf[2];
  1537.         canvas -edit -rgbValue $newColor[0] $newColor[1] $newColor[2] $canvasName;
  1538.     }    
  1539. }
  1540.  
  1541. // This function gets called from the apply tab if the data is
  1542. // "asColor" data and the user presses on the color canvas supplied.
  1543. // The appropriate calls are made if a change is confirmed
  1544. // to turn off any presets and set the value fields.
  1545. global proc bdeChangeColorData( int $id )
  1546. {
  1547.     $control = "bdeColorDataCanvas" + $id;
  1548.     if ( bdeChangeNamedCanvas( $control ) )
  1549.     {
  1550.         string $colStr[];
  1551.         string $colComp;
  1552.         float $col[] = `canvas -query -rgbValue $control`;
  1553.         for ( $i = 0; $i < 3; $i++ )
  1554.         {
  1555.             $colComp = $col[$i];
  1556.             $colStr[$i] = $colComp;
  1557.         }
  1558.         string $bdt = getTemplateNameFromId( $id );
  1559.         bdeSetControl( $bdt, $colStr );
  1560.         bdeChangedValue( $id );
  1561.     }
  1562. }
  1563.  
  1564. proc float absDiff( float $a, float $b )
  1565. {
  1566.     if ( $a >= $b )
  1567.         return $a - $b;
  1568.     else
  1569.         return $b - $a;
  1570. }
  1571.  
  1572. // See if two colors (rgb) are within $tol of one another
  1573. proc int colorsEquivalent( float $color1[], float $color2[], float $tol )
  1574. {
  1575.     for ( $i = 0; $i < 3; $i++ )
  1576.         if ( absDiff( $color1[$i], $color2[$i] ) > $tol )
  1577.             return false;
  1578.  
  1579.     return true;
  1580. }
  1581.  
  1582. // This function could use some work.
  1583. // It uses hard-coded values for 'distinct' colors, looks for 
  1584. // one of these hard-coded colors that's not in the given used 
  1585. // color list.
  1586. // I'd thought about using a colorIndexSliderGrp, but i wasn't
  1587. // sure whether the color table value was accessible and consistent
  1588. // across platforms and systems, and doesn't seem (on my system)
  1589. // to provide great colors
  1590. // Called by bdeGetUniqueColor
  1591. proc float[] getUnusedColor( float $usedR[], float $usedG[], float $usedB[], int $count )
  1592. {
  1593.     int $numDefaults = 11;
  1594.     float $r[] = { 1.00, 0.00, 0.00, 1.00, 0.00, 1.00, 0.70, 1.00, 0.50, 0.70, 0.35, 0.70, 0.70 };
  1595.     float $g[] = { 0.00, 1.00, 0.00, 1.00, 1.00, 0.00, 0.30, 0.50, 0.70, 1.00, 0.35, 0.70, 0.35 };
  1596.     float $b[] = { 0.00, 0.00, 1.00, 0.00, 1.00, 1.00, 0.40, 0.00, 0.70, 0.00, 0.70, 0.35, 0.35 };
  1597.     float $defaultColor[] = { 1, 1, 1 };
  1598.     float $newC[];
  1599.     float $usedC[];
  1600.  
  1601.     for ( $i = 0; $i < $numDefaults; $i++ )
  1602.     {
  1603.         $newC[0] = $r[$i]; $newC[1] = $g[$i]; $newC[2] = $b[$i];
  1604.         int $ok = true;
  1605.         for ( $j = 0; $j < $count; $j++ )
  1606.         {
  1607.             $usedC[0] = $usedR[$j]; $usedC[1] = $usedG[$j]; $usedC[2] = $usedB[$j];
  1608.             if ( colorsEquivalent( $newC, $usedC, 0.01 ) )
  1609.                 $ok = false;
  1610.         }
  1611.  
  1612.         if ( $ok )
  1613.             return $newC;
  1614.     }
  1615.     
  1616.     return $defaultColor;
  1617. }
  1618.  
  1619. // This function fills the usedColor arrays used by getUnusedColor
  1620. // with all of the appropriate canvases in the query color tab,
  1621. // and gets a new (unique) one. Not very robust/extensible.
  1622. proc float[] bdeGetUniqueColor()
  1623. {
  1624.     global string $bdeQueryColorLayout;
  1625.  
  1626.     float $usedR[];
  1627.     float $usedG[];
  1628.     float $usedB[];
  1629.     float $newColor[];
  1630.  
  1631.     string $children[] = `columnLayout -q -ca bdeQueryColorLayout`;
  1632.  
  1633.     for ( $i = 0; $i < size( $children ); $i++ )
  1634.     {        
  1635.         string $child = $children[$i];
  1636.         string $canvas = $bdeQueryColorLayout + "|" + $child + "|mainLine|canvas";
  1637.         if ( `canvas -q -ex $canvas` )
  1638.         {
  1639.             float $c[] = `canvas -query -rgbValue $canvas`;
  1640.             $usedR[$i] = $c[0]; $usedG[$i] = $c[1]; $usedB[$i] = $c[2];
  1641.         }
  1642.     }
  1643.     float $col[] = `canvas -query -rgbValue bdeClashColor`;
  1644.     $usedR[$i] = $col[0]; $usedG[$i] = $col[1]; $usedB[$i] = $col[2];
  1645.     $i++;
  1646.     $col = `canvas -query -rgbValue bdeOutOfRangeColor`;
  1647.     $usedR[$i] = $col[0]; $usedG[$i] = $col[1]; $usedB[$i] = $col[2];
  1648.     $i++;
  1649.     $col = `canvas -query -rgbValue bdeNoneColor`;
  1650.     $usedR[$i] = $col[0]; $usedG[$i] = $col[1]; $usedB[$i] = $col[2];
  1651.     $i++;
  1652.  
  1653.     $newColor = getUnusedColor( $usedR, $usedG, $usedB, $i );
  1654.     return $newColor;
  1655. }
  1656.  
  1657. // This function returns the value of the data as set in the apply tab
  1658. // for the specified template at the specified index
  1659. proc string bdeGetControl( string $bdt, int $index )
  1660. {
  1661.     if ( $bdt == "" )
  1662.         return "";
  1663.  
  1664.     int $id = getId( $bdt );
  1665.     string $controlName = "bdeDataValue" + $id + "_" + $index;
  1666.     string $dataType = getDataType( $bdt, $index );
  1667.     string $name = getLongName( $bdt, $index );
  1668.     string $ranged = getRanged( $bdt, $name );
  1669.     string $ret = "";
  1670.  
  1671.     if ( $dataType == "string" || $dataType == "binary" )
  1672.     {
  1673.         if ( `textField -q -ex $controlName` )
  1674.             $ret = `textField -q -tx $controlName`;
  1675.     }
  1676.     else if ( $dataType == "float" || $dataType == "double" )
  1677.     {
  1678.         if ( $ranged )
  1679.         {
  1680.             if ( `floatSliderGrp -q -ex $controlName` )
  1681.                 $ret = `floatSliderGrp -q -v $controlName`;
  1682.         }
  1683.         else
  1684.         {
  1685.             if ( `floatField -q -ex $controlName` )
  1686.             {
  1687.                 float $value = `floatField -q -v $controlName`;
  1688.                 $ret = $value;
  1689.             }
  1690.         }
  1691.     }
  1692.     else if ( $dataType == "int" )
  1693.     {
  1694.         if ( $ranged )
  1695.         {
  1696.             if ( `intSliderGrp -q -ex $controlName` )
  1697.                 $ret = `intSliderGrp -q -v $controlName`;
  1698.         }
  1699.         else
  1700.         {
  1701.             if ( `intField -q -ex $controlName` )
  1702.                 $ret = `intField -q -v $controlName`;
  1703.         }
  1704.     }
  1705.     else if ( $dataType == "hex" )
  1706.     {
  1707.         if ( `textField -q -ex $controlName` )
  1708.         {
  1709.             string $strVal = `textField -q -tx $controlName`;
  1710.             int $val = `hexStringToInt $strVal`;
  1711.             $ret = $val;
  1712.         }
  1713.     }
  1714.     else if ( $dataType == "boolean" )
  1715.     {
  1716.         if ( `radioButtonGrp -q -ex $controlName` )
  1717.         {
  1718.             int $val = `radioButtonGrp -q -sl $controlName`;
  1719.             $ret = --$val;
  1720.         }
  1721.     }
  1722.  
  1723.     return $ret;
  1724. }
  1725.  
  1726. // This function returns (in a string array) all of the data 
  1727. // set in the apply tab for the specified template node.
  1728. proc string[] bdeGetControls( string $bdt )
  1729. {
  1730.     string $controls[];
  1731.     int $dataCount = getDataCount( $bdt );
  1732.     for ( $i = 0; $i < $dataCount; $i++ )
  1733.     {
  1734.         $controls[$i] = bdeGetControl( $bdt, $i );
  1735.     }
  1736.  
  1737.     return $controls;
  1738. }
  1739.  
  1740. // This function gets called if any of the preset 
  1741. // radio buttons/check boxes change. It sets the 
  1742. // data value fields appropriately.
  1743. global proc bdeChangedPreset( int $id )
  1744. {    
  1745.     string $controlName;
  1746.     string $bdt = getTemplateNameFromId( $id );
  1747.     if ( $bdt == "" )
  1748.         return;
  1749.  
  1750.     string $applyMode = getApplyMode( $bdt );
  1751.     int $presetCount = getPresetCount( $bdt );
  1752.     int $dataCount = getDataCount( $bdt );
  1753.  
  1754.     if ( $applyMode == "hex" )
  1755.     {
  1756.         string $newStringVals[];
  1757.         for ( $i = 0; $i < $dataCount; $i++ )
  1758.             $newStringVals[$i] = "0";
  1759.         for ( $i = 0; $i < $presetCount; $i++ )
  1760.         {            
  1761.             $controlName = "bdeIndicator" + $id + "_" + $i;
  1762.             if ( `checkBox -q -v $controlName` )
  1763.             {                
  1764.                 for ( $j = 0; $j < $dataCount; $j++ )
  1765.                 {
  1766.                     string $attr = getLongName( $bdt, $j );
  1767.                     string $thisVal = getPresetVal( $bdt, $i, $attr );
  1768.                     $newStringVals[$j] = orHexString( $newStringVals[$j], $thisVal );
  1769.                 }
  1770.             }            
  1771.         }
  1772.         bdeSetControl( $bdt, $newStringVals );
  1773.     }
  1774.     else
  1775.     {
  1776.         for ( $i = 0; $i < $presetCount; $i++ )
  1777.         {
  1778.             string $newVals[];
  1779.             $controlName = "bdeIndicator" + $id + "_" + $i;
  1780.             if ( `radioButton -q -sl $controlName` )
  1781.             {
  1782.                 $newVals = getPresetVals( $bdt, $i );
  1783.                 bdeSetControl( $bdt, $newVals );
  1784.                 return;
  1785.             }
  1786.         }
  1787.     }
  1788. }
  1789.  
  1790. // Controls which frame to open. There are three frames,
  1791. // which the user can switch between if the data type is
  1792. // int or float and free set is set.
  1793. // This function closes the two others and
  1794. // opens the specified one based on the value of the applyType 
  1795. // optionMenu.
  1796. global proc bdeChangeApplyType( int $id )
  1797. {
  1798.     string $absFrame = "bdeAbsoluteFrame" + $id;
  1799.     string $offFrame = "bdeOffsetFrame" + $id;
  1800.     string $scaFrame = "bdeScaleFrame" + $id;
  1801.     string $preFrame = "bdePresetFrame" + $id;
  1802.  
  1803.     string $control = "bdeApplyType" + $id;
  1804.     string $applyType = `optionMenu -q -v $control`;
  1805.     if ( "Absolute" == $applyType )
  1806.     {
  1807.         frameLayout -e -cl false $preFrame;
  1808.         frameLayout -e -cl false $absFrame;
  1809.         frameLayout -e -cl true $offFrame;
  1810.         frameLayout -e -cl true $scaFrame;
  1811.     }
  1812.     else if ( "Offset" == $applyType )
  1813.     {
  1814.         frameLayout -e -cl true $preFrame;
  1815.         frameLayout -e -cl true $absFrame;
  1816.         frameLayout -e -cl false $offFrame;
  1817.         frameLayout -e -cl true $scaFrame;
  1818.     }
  1819.     else if ( "Scale" == $applyType )
  1820.     {
  1821.         frameLayout -e -cl true $preFrame;
  1822.         frameLayout -e -cl true $absFrame;
  1823.         frameLayout -e -cl true $offFrame;
  1824.         frameLayout -e -cl false $scaFrame;
  1825.     }
  1826. }
  1827.  
  1828. // Returns whether relative controls (offset, scale)
  1829. // make sense for the given template.
  1830. // If any of the types are not int or double, or if
  1831. // free set is not true (meaning that user can only choose
  1832. // the predifined presets), then this returns false
  1833. // and the relativeControls are not created or accessible.
  1834. proc int relativeControls( string $bdt )
  1835. {
  1836.     if ( !getFreeSet( $bdt ) )
  1837.         return 0;
  1838.  
  1839.     int $dataCount = getDataCount( $bdt );
  1840.     for ( $i = 0; $i < $dataCount; $i++ )
  1841.     {
  1842.         string $dataType = getDataType( $bdt, $i );
  1843.         if ( $dataType == "string" || $dataType == "binary" || 
  1844.              $dataType == "boolean" || $dataType == "hex" )
  1845.              return 0;        
  1846.     }
  1847.  
  1848.     return 1;
  1849. }
  1850.  
  1851. // Create a frame that has a floatSlider for each of the 
  1852. // attributes in the blindDataTemplate.
  1853. // The slider initially has a range of [-10,10], but by
  1854. // typing in the float field boxes user can expand these
  1855. // to [-100000,100000], which should be high enough for anything.
  1856. // Note that you have to specify a field min/max (-fmn/-fmx)
  1857. // in the floatSliderGrp creation, or the value is taken to
  1858. // be the min/max.
  1859. proc createScaleControls( string $bdt )
  1860. {
  1861.     if ( $bdt == "" )
  1862.         return;
  1863.  
  1864.     float $floatMin = -100000, 
  1865.           $floatMax = 100000;
  1866.  
  1867.     int $freeSet = getFreeSet( $bdt );
  1868.     int $id = getId( $bdt );
  1869.  
  1870.     string $control = "bdeScaleFrame" + $id;
  1871.     frameLayout -cll true -cl true -bv false -lv false $control;
  1872.         columnLayout -adj true -rs 5;
  1873.  
  1874.             int $dataCount = getDataCount( $bdt );
  1875.             for ( $i = 0; $i < $dataCount; $i++ )
  1876.             {
  1877.                 string $dataType = getDataType( $bdt, $i );
  1878.                 if ( $dataType == "string" || $dataType == "binary" || 
  1879.                      $dataType == "boolean" || $dataType == "hex" )
  1880.                     continue;;
  1881.  
  1882.                 if ( !$freeSet )
  1883.                     continue;
  1884.  
  1885.                 $controlName = "bdeDataScale" + $id + "_" + $i;
  1886.                 string $text = getLongName( $bdt, $i );
  1887.  
  1888.                 rowLayout -nc 2 -cw 1 80 -cw 2 400;
  1889.                     text -l $text;
  1890.                     $max = 10;
  1891.                     $min = -10;
  1892.  
  1893.                     floatSliderGrp -f true -min $min -max $max 
  1894.                         -fmn $floatMin -fmx $floatMax -v 1 $controlName;
  1895.                 setParent ..;
  1896.             }
  1897.         setParent ..;
  1898.     setParent ..;
  1899.  
  1900. }
  1901.  
  1902. // Create slider grp for each of the attributes in the blind data template.
  1903. // If the data is int, an intSliderGrp is created, if float, a floatSliderGrp
  1904. // is created.
  1905. // If the data for each attribute is ranged, then
  1906. //  min = getMinVal() - getMaxVal(); max = getMaxVal() - getMinVal()
  1907. // otherwise, range is [-1,1] for double data and [-100,100] for int data.
  1908. // Again, these are initial ranges - by typing in numbers in the numeric fields,
  1909. // you can get a range of [-100000,100000].
  1910. proc createOffsetControls( string $bdt )
  1911. {
  1912.     if ( $bdt == "" )
  1913.         return;
  1914.  
  1915.     float $floatMin = -100000, 
  1916.           $floatMax = 100000;
  1917.  
  1918.     int $freeSet = getFreeSet( $bdt );
  1919.     int $id = getId( $bdt );
  1920.  
  1921.     string $control = "bdeOffsetFrame" + $id;
  1922.     frameLayout -cll true -cl true -bv false -lv false $control;
  1923.         columnLayout -adj true -rs 5;
  1924.  
  1925.             int $dataCount = getDataCount( $bdt );
  1926.             for ( $i = 0; $i < $dataCount; $i++ )
  1927.             {
  1928.                 string $dataType = getDataType( $bdt, $i );
  1929.                 // Neither of these two should be true if this frame was 
  1930.                 // created, but we check just to be sure
  1931.                 if ( $dataType == "string" || $dataType == "binary" || 
  1932.                      $dataType == "boolean" || $dataType == "hex" )
  1933.                     continue;
  1934.  
  1935.                 if ( !$freeSet )
  1936.                     continue;
  1937.  
  1938.                 string $attrName = getLongName( $bdt, $i );
  1939.  
  1940.                 int $ranged = getRanged( $bdt, $attrName );
  1941.                 float $min, $max;
  1942.  
  1943.                 $controlName = "bdeDataOffset" + $id + "_" + $i;
  1944.  
  1945.                 rowLayout -nc 2 -cw 1 80 -cw 2 400;
  1946.                     text -l $attrName;
  1947.                     
  1948.                     if ( $ranged )
  1949.                     {
  1950.                         float $tmpMin = getMinVal( $bdt, $attrName );
  1951.                         float $tmpMax = getMaxVal( $bdt, $attrName );
  1952.                         $min = $tmpMin - $tmpMax;
  1953.                         $max = $tmpMax - $tmpMin;
  1954.                     }
  1955.                     else
  1956.                     {
  1957.                         if ( $dataType == "int" )
  1958.                             $max = 100;
  1959.                         else
  1960.                             $max = 1.0;
  1961.  
  1962.                         $min = -$max;
  1963.                     }
  1964.  
  1965.                     if ( $dataType == "int" )
  1966.                         intSliderGrp -f true -min $min -max $max 
  1967.                             -fmn $floatMin -fmx $floatMax -v 0 $controlName;
  1968.                     else
  1969.                         floatSliderGrp -f true -min $min -max $max 
  1970.                             -fmn $floatMin -fmx $floatMax -v 0 $controlName;
  1971.                 setParent ..;
  1972.             }
  1973.         setParent ..;
  1974.     setParent ..;
  1975. }
  1976.  
  1977. // The absolute controls are the default for the apply tab,
  1978. // and the only ones if relativeControls() for this $bdt returns false.
  1979. proc createAbsoluteControls( string $bdt )
  1980. {
  1981.     if ( $bdt == "" )
  1982.         return;
  1983.  
  1984.     int $id = getId( $bdt );
  1985.     string $controlName = "bdeAbsoluteFrame" + $id;
  1986.  
  1987.     // bdeChangedValue gets called if any of the 'value' 
  1988.     // fields/sliders/radiobuttons get changed (by the user)
  1989.     string $changeCommand = "bdeChangedValue (" + $id + ")";
  1990.  
  1991.     string $dataTypes[];
  1992.     int $ranged[];
  1993.     int $min[];
  1994.     int $max[];
  1995.     int $freeSet = getFreeSet( $bdt );
  1996.  
  1997.     // The main frame for this set of controls
  1998.     frameLayout -cll true -cl false -bv false -lv false $controlName;
  1999.         columnLayout -adj true -rs 6;
  2000.             int $dataCount = getDataCount( $bdt );    
  2001.             for ( $i = 0; $i < $dataCount; $i++ )
  2002.             {
  2003.                 string $attr = getLongName( $bdt, $i );
  2004.  
  2005.                 // $controlName here is the same regardless of the type
  2006.                 // of control we're making.
  2007.                 $controlName = "bdeDataValue" + $id + "_" + $i;
  2008.  
  2009.                 $dataTypes[$i] = getDataType( $bdt, $i );                
  2010.                 $ranged[$i] = getRanged( $bdt, $attr );
  2011.  
  2012.                 // For string/binary data, create a textField.
  2013.                 if ( $dataTypes[$i] == "string" || $dataTypes[$i] == "binary" )
  2014.                 {
  2015.                     rowLayout -nc 2 -cw 1 80 -cw 2 120;
  2016.                         text -l $attr;
  2017.                         textField -cc $changeCommand $controlName;
  2018.  
  2019.                         // Disable the textField if user can't freely set it.
  2020.                         // (This prevents the user from entering values that
  2021.                         // the game engine doesn't support)
  2022.                         if ( !$freeSet )
  2023.                             textField -e -en false $controlName;
  2024.                     setParent ..;
  2025.                 }
  2026.                 // For hex types, we also create a textField. MEL doesn't support
  2027.                 // hex data in numeric fields, so we've got to internally convert
  2028.                 // and set the data.
  2029.                 else if ( $dataTypes[$i] == "hex" )
  2030.                 {
  2031.                     rowLayout -nc 2 -cw 1 80 -cw 2 90;
  2032.                         text -l $attr;
  2033.                         textField -w 90 -tx "0x0000" -cc $changeCommand $controlName;
  2034.                         // Again, disable the textField if user can't freely set it
  2035.                         if ( !$freeSet )
  2036.                             textField -e -en false $controlName;
  2037.                     setParent ..;
  2038.                 }
  2039.                 // Create a couple of radioButtons for boolean data
  2040.                 // (Doesn't make sense to test for 'freeSet' here because data can
  2041.                 // only be one of two values regardless)
  2042.                 else if ( $dataTypes[$i] == "boolean" )
  2043.                 {
  2044.                     rowLayout -nc 2 -cw 1 80 -cw 2 400;
  2045.                         text -l $attr;
  2046.                         radioButtonGrp -nrb 2 -l1 "false" -l2 "true" 
  2047.                             -cc $changeCommand $controlName;
  2048.                         radioButtonGrp -e -sl 1 $controlName;
  2049.                     setParent ..;
  2050.                 }
  2051.                 // If we're here we've got numeric (int or float) data
  2052.                 else 
  2053.                 {
  2054.                     // Again, we disable the control if user can't free set data.
  2055.                     rowLayout -nc 2 -cw 1 80 -cw 2 400;
  2056.                         text -l $attr;
  2057.                         // If this attr is ranged, we'll want to
  2058.                         // make sliders.
  2059.                         if ( $ranged[$i] )
  2060.                         {
  2061.                             $min[$i] = getMinVal( $bdt, $attr );
  2062.                             $max[$i] = getMaxVal( $bdt, $attr );
  2063.                             if ( $dataTypes[$i] == "int" )
  2064.                             {
  2065.                                 intSliderGrp -f true -cc $changeCommand 
  2066.                                     -min $min[$i] -max $max[$i] $controlName;
  2067.                                 if ( !$freeSet )
  2068.                                     intSliderGrp -e -en false $controlName;
  2069.                             }
  2070.                             else
  2071.                             {
  2072.                                 floatSliderGrp -step .0001 -f true -cc $changeCommand 
  2073.                                     -min $min[$i] -max $max[$i] $controlName;
  2074.                                 if ( !$freeSet )
  2075.                                     floatSliderGrp -e -en false $controlName;
  2076.                             }
  2077.                         }
  2078.                         // Not ranged - just use a numeric field.
  2079.                         else
  2080.                         {
  2081.                             if ( $dataTypes[$i] == "int" )
  2082.                             {
  2083.                                 intField -cc $changeCommand $controlName;
  2084.                                 if ( !$freeSet )
  2085.                                     intField -e -en false $controlName;
  2086.                             }
  2087.                             else
  2088.                             {
  2089.                                 floatField -cc $changeCommand $controlName;
  2090.                                 if ( !$freeSet)
  2091.                                     floatField -e -en false $controlName;
  2092.                             }
  2093.                         }            
  2094.                     setParent ..;
  2095.                 }                
  2096.         }
  2097.     
  2098.         // If the data looks like it could be construed as color
  2099.         // (i.e. 3 floats, [0,1]), we create a canvas for users to 
  2100.         // select values with.
  2101.         string $applyMode = getApplyMode( $bdt );
  2102.         if ( $applyMode == "asColor" )
  2103.         {            
  2104.             rowLayout -nc 2 -cw 1 80 -cw 2 400;
  2105.                 separator -st "none";
  2106.                 string $changeColorCommand = "bdeChangeColorData( " + $id + " )";
  2107.                 $controlName = "bdeColorDataCanvas" + $id;
  2108.                 canvas -w 80 -h 25 -pc $changeColorCommand -rgbValue 0 0 0 $controlName;
  2109.             setParent ..;
  2110.         }            
  2111.         setParent ..;
  2112.     setParent ..;
  2113. }
  2114.  
  2115. // This func deletes all of the children of the
  2116. // main apply tab.
  2117. global proc bdeDeleteApplyUI()
  2118. {
  2119.     string $parent = "bdeSingleApplyLayout";
  2120.  
  2121.     if ( `tabLayout -q -ex $parent` )
  2122.     {
  2123.         string $children[] = `tabLayout -q -ca $parent`;
  2124.         for ( $child in $children )
  2125.             deleteUI -lay $child;
  2126.     }
  2127. }
  2128.  
  2129. // This function does the work of rebuilding the UI used for
  2130. // applying blind data for the blind data template with the given id.
  2131. // If the id is valid, a columnLayout is created as a child of the
  2132. // main Apply tab.
  2133. // It returns the name of the newly created columnLayout, or an empty
  2134. // string if a layout is not created.
  2135. global proc string bdeRebuildApplyTab( int $id )
  2136. {
  2137.     if ( !idDefined( $id ) )
  2138.         return "";
  2139.  
  2140.     string $bdt = getTemplateNameFromId( $id );
  2141.     if ( $bdt == "" )
  2142.         return "";
  2143.  
  2144.     string                $controlName;
  2145.     string                $firstRadio;
  2146.     string                $assocType;
  2147.     string                $tag;
  2148.     string                $text;
  2149.     string                $dataType[];
  2150.     string                $longName[];
  2151.     int                    $i, $j;
  2152.     string                $applyMode = getApplyMode( $bdt );
  2153.  
  2154.     // What we call this tab (internally)
  2155.     string $thisTab = "bdeApply" + $id;
  2156.  
  2157.     // The label of this tab. The parent tab (bdeSingleApplyLayout)
  2158.     // does not currently display the tabs of it's child layouts.
  2159.     // If this is to change then this label is useful for accessing the tabs.
  2160.     string $thisTabLabel = getTag( $bdt );
  2161.     if ( $thisTabLabel == "" )
  2162.         $thisTabLabel = "" + $id;
  2163.  
  2164.     // Parent this layout underneath the main apply tab
  2165.     setParent bdeSingleApplyLayout;
  2166.     columnLayout -adj true $thisTab;    
  2167.     
  2168.     int $dataCount = getDataCount( $bdt );
  2169.     // Display the name(s) and type for each of the attr's in 
  2170.     // the given template.
  2171.     for ( $i = 0; $i < $dataCount; $i++ )
  2172.     {
  2173.         rowColumnLayout -nc 2;
  2174.  
  2175.             text -l "Long name:";
  2176.             $controlName = "bdeLongDataName" + $id + "_" + $i;
  2177.             $longName[$i] = getLongName( $bdt, $i );
  2178.             text -l $longName[$i] $controlName;
  2179.             // Uncomment out the following to display short names.
  2180. /*
  2181.             text -l "Short name:";
  2182.             $controlName = "bdeShortDataName" + $id + "_" + $i;
  2183.             $text = getShortName( $bdt, $i );
  2184.             text -l $text $controlName;
  2185. */        
  2186.             text -l "Type:";
  2187.             $controlName = "bdeDataType" + $id + "_" + $i;
  2188.             $dataType[$i] = getDataType( $bdt, $i );
  2189.             text -l $dataType[$i] $controlName;
  2190.                 
  2191.         setParent ..;
  2192.  
  2193.         separator -w 400 -h 8 -st "in";
  2194.     }
  2195.  
  2196.     $numPresets = getPresetCount( $bdt );
  2197.  
  2198.     // What gets called if the presets are changed.
  2199.     string $changedCmd = "bdeChangedPreset (" + $id + ")";
  2200.  
  2201.     // A frame layout for the presets so we can close it to 
  2202.     // restrict access. The border is invisible, so user can't collapse.
  2203.     // could set -bv to true if there's too much clutter and presets aren't
  2204.     // always used.
  2205.     $controlName = "bdePresetFrame" + $id;    
  2206.     frameLayout -cll true -cl false -lv false -bv false $controlName;
  2207.         string $row = `rowColumnLayout -nc 3`;
  2208.         // Use $applyMode (getApplyMode( $bdt )) to see whether we
  2209.         // should use radioButtons or checkboxes. If any of the data
  2210.         // types are hex we use checkboxes. This may be problematic
  2211.         // if there are multiple attributes and not all are hex.
  2212.         // It's not clear to me how to handle this case.
  2213.             if ( $applyMode != "hex" )
  2214.             {
  2215.                 $controlName = $row + "|radioCollection";
  2216.                 radioCollection $controlName;
  2217.  
  2218.                 // We make the first in the collection invisible
  2219.                 // so that we can select it to turn all the rest off.
  2220.                 $controlName = "bdeNoIndicator" + $id;
  2221.                 $firstRadio = `radioButton -vis false -h 1 $controlName`;
  2222.                 separator -st "none";
  2223.                 separator -st "none";
  2224.             }
  2225.     
  2226.             for ( $i = 0; $i < $numPresets; $i++ )
  2227.             {            
  2228.                 $controlName = "bdeIndicator" + $id + "_" + $i;
  2229.                 if ( $applyMode == "hex" )
  2230.                     checkBox -cc $changedCmd -l "" $controlName;
  2231.                 else
  2232.                     radioButton -l "" -cc $changedCmd $controlName;
  2233.                 $presetName = getPresetName( $bdt, $i );
  2234.                 text -l $presetName;
  2235.                 
  2236.                 for ( $j = 0; $j < $dataCount; $j++ )
  2237.                 {
  2238.                     if ( $j != 0 )
  2239.                     {
  2240.                         separator -st "none";
  2241.                         separator -st "none";
  2242.                     }
  2243.                     $presetVal = getPresetVal( $bdt, $i, $longName[$j] );
  2244.                     text -l $presetVal;
  2245.                 }
  2246.             }
  2247.         setParent ..;
  2248.     setParent ..;
  2249.  
  2250.     if ( $numPresets > 0 )
  2251.     {
  2252.         columnLayout -adj true;
  2253.             separator -w 325 -h 15 -st "in";
  2254.         setParent ..;        
  2255.     }
  2256.  
  2257.     rowLayout -nc 4 -cw 1 80 -cw 2 90 -cw 3 80 -cw 4 90;
  2258.         
  2259.         text -l "Assoc type";
  2260.         $controlName = "bdeAssocType" + $id;
  2261.         optionMenu $controlName;
  2262.             menuItem -label "face";
  2263.             menuItem -label "vertex";
  2264.             // BlindDataTemplate supports edge types, but it doesn't seem too many
  2265.             // people use edges for blind data (and we can't false color edges!).
  2266.             // Easy enough to comment this out, however, and should work, or if not,
  2267.             // minor changes should be involved (to assign and query the data at least)
  2268. //            menuItem -label "edge";
  2269.             // VertexFace blind data is not fully supported in Maya right now
  2270. //            menuItem -label "vertexFace";
  2271.             menuItem -label "object";
  2272.         $assocType = getAssocType( $bdt );
  2273.         // It could be that $assocType is empty, 
  2274.         // if this template wasn't set up through the type editor
  2275.         if ( $assocType == "" ) 
  2276.             $assocType = "any";
  2277.  
  2278.         if ( $assocType != "any" )
  2279.             optionMenu -e -v $assocType -en false $controlName;
  2280.  
  2281.         text -l "Apply type";
  2282.         string $cmd = "bdeChangeApplyType (" + $id + ")";
  2283.         $controlName = "bdeApplyType" + $id;
  2284.         optionMenu -cc $cmd $controlName;
  2285.             menuItem -l "Absolute";
  2286.             menuItem -l "Offset";
  2287.             menuItem -l "Scale";
  2288.             
  2289.         // We just disable the optionMenu (set at the default value
  2290.         // of "Absolute") if `relativeControls` == false.
  2291.         if ( !relativeControls( $bdt ) )
  2292.             optionMenu -e -en false $controlName;
  2293.  
  2294.     setParent ..;
  2295.     separator -w 400 -h 8 -st "in";
  2296.  
  2297.     createAbsoluteControls( $bdt );
  2298.     // Should really check if relativeControls is true here
  2299.     // before creating all the controls. Creating UI is not a real
  2300.     // fast process. However, some changes to at least bdeChangeApplyType
  2301.     // (to check if the frames exist, etc.) would have to be made in this case,
  2302.     // It's too late to make these changes.
  2303.     createOffsetControls( $bdt );
  2304.     createScaleControls( $bdt );
  2305.  
  2306.     // Call this to set the proper frame collapse settings, etc.
  2307.     bdeChangeApplyType( $id );
  2308.  
  2309.     setParent ..; // This tab
  2310.  
  2311.     tabLayout -e -tabLabel $thisTab $thisTabLabel bdeSingleApplyLayout;
  2312.  
  2313.     return $thisTab;
  2314. }
  2315.  
  2316. // This function checks the current apply selection,
  2317. // (re)builds the layout if necessary, and sets the
  2318. // main apply tab (bdeSingleApplyLayout) to have this
  2319. // layout as it's 'selected tab' (visible).
  2320. global proc bdeRebuildApply()
  2321. {
  2322.     string $mainLayout = "bdeMainColumnLayout";
  2323.     string $bdt = getCurrentApplyTemplate();
  2324.     if ( $bdt == "" )
  2325.         return;
  2326.  
  2327.     int $id = getId( $bdt );
  2328.  
  2329.     string $tab = getApplyTab( $id );
  2330.     if ( $tab == "" )
  2331.         $tab = bdeRebuildApplyTab( $id );
  2332.     
  2333.     tabLayout -e -st $tab bdeSingleApplyLayout;
  2334. }
  2335.  
  2336. // There are two text scroll lists - one in the apply tab and
  2337. // one in the type editor tab. These lists are present so that
  2338. // the whole gamut of blind data templates are available in one
  2339. // control and can be fairly quickly selected.
  2340. // We create the entries to look like
  2341. // tag (#)
  2342. // if a tag exists (and # indicates the numeric id) or just
  2343. // #
  2344. // if there is no tag for a template.
  2345. global proc bdeRebuildTextScrollLists()
  2346. {
  2347.     string        $cmd, $cmdName;
  2348.     string        $tag;
  2349.     string        $item;
  2350.     string        $blindDataTag[];
  2351.     string        $blindDataId[];
  2352.     string        $lists[] = { "bdeTypeList", "bdeTemplateList" };
  2353.     // Bug 150384 check exact type so we don't get subd blind data
  2354.     string        $nodes[] = `ls -exactType blindDataTemplate`;
  2355.  
  2356.     for ( $i = 0; $i < size( $nodes ); $i++ )
  2357.     {
  2358.         $blindDataId[$i] = getId( $nodes[$i] );
  2359.         $blindDataTag[$i] = getTag( $nodes[$i] );
  2360.     }
  2361.  
  2362.     $cmd = "textScrollList -e";
  2363.     for ( $i = 0; $i < size( $nodes ); $i++ )
  2364.     {
  2365.         if ( $blindDataTag[$i] != "" )
  2366.             $tag = $blindDataTag[$i] + " (" + $blindDataId[$i] + ")";
  2367.         else
  2368.             $tag = $blindDataId[$i];
  2369.  
  2370.         $cmd += " -append \"";
  2371.         $cmd += $tag + "\"";
  2372.     }
  2373.  
  2374.     for ( $list in $lists )
  2375.     {
  2376.         if ( `textScrollList -q -ex $list` )
  2377.         {
  2378.             textScrollList -e -removeAll $list;
  2379.             $cmdName = $cmd + " " + $list;
  2380.             eval( $cmdName );
  2381.         }
  2382.     }
  2383. }
  2384.  
  2385. // Note that the passed in $layout here should not be the whole
  2386. // Qc layout, but "$layout|multiList" or the whole row will get
  2387. // axed.
  2388.  
  2389. // The frameLayout should be collapsed or we'll get flicker!
  2390. global proc bdeQcDeleteMultiList( string $layout )
  2391. {
  2392.     string $children[] = `frameLayout -q -ca $layout`;
  2393.     for ( $child in $children )
  2394.     {
  2395.         deleteUI -lay $child;
  2396.     }
  2397. }
  2398.  
  2399. // Build the layout for the multi.
  2400. // We create and delete it each time to ease the 
  2401. // case of switching to a new type that isn't a multi
  2402. // or has a different number of attrs.
  2403. // Returns 1 if the layout was built, 0 if not.
  2404. global proc int bdeQcBuildMultiList( string $parent )
  2405. {
  2406.     string $controlName;
  2407.     string $longName;
  2408.     string $layout = $parent + "|multiList";
  2409.  
  2410.     string $bdt = getQcSelectedBdt( $parent );
  2411.     if ( $bdt == "" )
  2412.         return 0;
  2413.     
  2414.     bdeQcDeleteMultiList( $layout );
  2415.  
  2416.     int $dataCount = getDataCount( $bdt );
  2417.     if ( $dataCount > 1 )
  2418.     {
  2419.         setParent $layout;
  2420.         // We create a columnLayout, and then create a 
  2421.         // rowLayout for each attribute to ease the ability
  2422.         // to access the controls.
  2423.         // Have to have the columnLayout because the parent's a 
  2424.         // frameLayout, which can only have one child.
  2425.         columnLayout dataLayout;
  2426.         for ( $i = 1; $i < $dataCount; $i++ )
  2427.         {
  2428.             $controlName = "rowLayout" + $i;
  2429.             rowLayout -ut bdeQcMainLineTemplate $controlName;
  2430.                 // Would be faster and more efficient to have these
  2431.                 // row layouts be templated to be the right sizes and
  2432.                 // not use these separators, but i didn't have time to
  2433.                 // get the right values.
  2434.                 // Using the separators is slower, but ensures that everything
  2435.                 // is correctly aligned.
  2436.                 separator -st "none";
  2437.                 separator -st "none";
  2438.                 separator -st "none";
  2439.                 $longName = getLongName( $bdt, $i );
  2440.                 text -l $longName longName;
  2441.                 textField -w 90 -cc ( "bdeQcChangedValue \"" + $parent + "\"" ) value;
  2442.                 separator -st "none";
  2443.             setParent ..;
  2444.         }
  2445.         setParent ..;
  2446.         
  2447.         return 1;
  2448.     }
  2449.     else
  2450.         return 0;
  2451. }
  2452.  
  2453. // This func determines whether the canvas on the given qc line
  2454. // should be disabled (and blacked out). If so, it stores the old
  2455. // color in the invisible 'saveCanvas', blacks out the color, and
  2456. // disables the canvas.
  2457. // The canvas is blacked and disabled if the template exists and
  2458. // the value type is set to continuous or asColor. 
  2459. global proc bdeQcDoColorSwap( string $parent )
  2460. {
  2461.     global string $bdeContinuousName;
  2462.     global string $bdeAsColorName;
  2463.     string $mainLine = $parent + "|mainLine";
  2464.     string $form = $parent + "|valueLayout|valueForm";
  2465.     string $mainCanvas = $mainLine + "|canvas";
  2466.     string $saveCanvas = $parent + "|valueLayout|valueForm|valueTypeLayout|saveColor";
  2467.  
  2468.     float $noColor[] = { 0, 0, 0 };
  2469.  
  2470.     string $bdt = getQcSelectedBdt( $parent );
  2471.  
  2472.     $control = $mainLine + "|valueEnable";
  2473.     int $valueEnabled = `checkBox -q -v $control`;
  2474.     int $disableIt;
  2475.     if ( $bdt == "" || !$valueEnabled )
  2476.         $disableIt = false;
  2477.     else
  2478.     {
  2479.         string $om = $form + "|valueTypeLayout|valueType";    
  2480.         string $selectType = `optionMenu -q -v $om`;
  2481.         if ( $selectType == $bdeContinuousName || $selectType == $bdeAsColorName )
  2482.             $disableIt = true;
  2483.         else
  2484.             $disableIt = false;
  2485.     }
  2486.  
  2487.     if ( $disableIt )
  2488.     {
  2489.         // It may have been disabled already. In this case, we don't want to
  2490.         // save the black color.
  2491.         canvas -e -pc "" $mainCanvas;
  2492.         float $col[] = `canvas -query -rgbValue $mainCanvas`;
  2493.         canvas -edit -rgbValue $noColor[0] $noColor[1] $noColor[2] $mainCanvas;
  2494.         if ( !colorsEquivalent( $noColor, $col, 0.001 ) )
  2495.         {
  2496.             canvas -edit -rgbValue $col[0] $col[1] $col[2] $saveCanvas;
  2497.         }
  2498.     }
  2499.     else
  2500.     {
  2501.         canvas -e -pc ( "bdeChangeCanvas \"" + $parent + "\"" ) $mainCanvas;
  2502.         float $col[] = `canvas -query -rgbValue $saveCanvas`;
  2503.         canvas -edit -rgbValue $col[0] $col[1] $col[2] $mainCanvas;
  2504.     }
  2505. }
  2506.  
  2507. global proc string bdeQcCGetTab( string $selectType )
  2508. {
  2509.     global string        $bdeDiscreteValName;
  2510.     global string        $bdeDiscreteRangeName;
  2511.     global string        $bdeHexValName;
  2512.     global string        $bdeContinuousName;
  2513.     global string        $bdeAsColorName;
  2514.  
  2515.     string $desiredTab = "chooser";
  2516.     if ( $selectType == $bdeDiscreteValName )
  2517.         $desiredTab += "DV";
  2518.     else if ( $selectType == $bdeDiscreteRangeName )
  2519.         $desiredTab += "DR";
  2520.     else if ( $selectType == $bdeHexValName )
  2521.         $desiredTab += "U";
  2522.     else if ( $selectType == $bdeContinuousName )
  2523.         $desiredTab += "C";
  2524.     else if ( $selectType == $bdeAsColorName)
  2525.         $desiredTab += "AC";
  2526.  
  2527.     return $desiredTab;
  2528. }
  2529.  
  2530. // Called automatically if the user changes one of the values.
  2531. // If this is the case the presets are turned off.
  2532. global proc bdeQcChangedValue( string $parent )
  2533. {
  2534.     global string        $bdeDiscreteValName;
  2535.     global string        $bdeHexValName;
  2536.  
  2537.     string $mainLine = $parent + "|mainLine";
  2538.     string $form = $parent + "|valueLayout|valueForm";
  2539.     string $tab = $form + "|valueChooser";
  2540.     string $om = $form + "|valueTypeLayout|valueType";    
  2541.  
  2542.     string $bdt = getQcSelectedBdt( $parent );
  2543.     if ( $bdt == "" )
  2544.         return;
  2545.  
  2546.     string $value;
  2547.  
  2548.     string $selectType = `optionMenu -q -v $om`;
  2549.     string $thisLayout = bdeQcCGetTab( $selectType );
  2550.  
  2551.     if ( $selectType == $bdeDiscreteValName )
  2552.     {
  2553.         string $layout = $tab + "|" + $thisLayout + "|dvLayout";
  2554.         $control = $layout + "|qccNoIndicator";
  2555.         radioButton -e -sl $control;
  2556.     }
  2557.     else if ( $selectType == $bdeHexValName )
  2558.     {
  2559.         string $layout = $tab + "|" + $thisLayout + "|uLayout|uDataLayout";
  2560.         int $numPresets = getPresetCount( $bdt );
  2561.         for ( $i = 0; $i < $numPresets; $i++ )
  2562.         {
  2563.             $control = $layout + "|qccIndicator" + $i;
  2564.             checkBox -e -v 0 $control;
  2565.         }
  2566.     }
  2567. }
  2568.  
  2569. // Set the value of the given row for the given index.
  2570. // This gets called by changing the preset, using the
  2571. // value chooser, etc.
  2572. global proc bdeQcSetValue( string $parent, int $index, string $value )
  2573. {
  2574.     string $mainLine = $parent + "|mainLine";        
  2575.  
  2576.     if ( $index == 0 )
  2577.     {
  2578.         $control = $mainLine + "|value";
  2579.         textField -e -tx $value $control;
  2580.     }
  2581.     else
  2582.     {    
  2583.         string $layout = $parent + "|multiList|dataLayout|rowLayout" + $index;
  2584.         if ( `rowLayout -q -ex $layout` )
  2585.         {
  2586.             $control = $layout + "|value";
  2587.             textField -e -tx $value $control;
  2588.         }
  2589.     }
  2590. }
  2591.  
  2592. // This sets up the value fields for the given qc row with
  2593. // the values from the value chooser frame (ranged data,
  2594. // presets, continuous, etc.)
  2595. global proc bdeSetQcValues( string $parent )
  2596. {
  2597.     global string        $bdeDiscreteValName;
  2598.     global string        $bdeDiscreteRangeName;
  2599.     global string        $bdeHexValName;
  2600.     global string        $bdeContinuousName;
  2601.     global string        $bdeAsColorName;
  2602.  
  2603.     string $mainLine = $parent + "|mainLine";
  2604.     string $form = $parent + "|valueLayout|valueForm";
  2605.     string $tab = $form + "|valueChooser";
  2606.     string $om = $form + "|valueTypeLayout|valueType";
  2607.  
  2608.     string $bdt = getQcSelectedBdt( $parent );
  2609.     if ( $bdt == "" )
  2610.         return;
  2611.  
  2612.     int $dataCount = getDataCount( $bdt );
  2613.     int $numTags;
  2614.     string $value;
  2615.  
  2616.     string $selectType = `optionMenu -q -v $om`;
  2617.     string $thisLayout = bdeQcCGetTab( $selectType );
  2618.  
  2619.     // Discrete value just puts the values corresponding
  2620.     // to the selected (if any) preset into the value fields.
  2621.     if ( $selectType == $bdeDiscreteValName )
  2622.     {
  2623.         string $layout = $tab + "|" + $thisLayout + "|dvLayout";        
  2624.         
  2625.         for ( $j = 0; $j < $dataCount; $j++ )
  2626.             bdeQcSetValue( $parent, $j, "" );
  2627.  
  2628.         $numPresets = getPresetCount( $bdt );
  2629.         for ( $i = 0; $i < $numPresets; $i++ )
  2630.         {
  2631.             $preset = getPresetName( $bdt, $i );            
  2632.             $control = $layout + "|qccIndicator" + $i;
  2633.             if ( `radioButton -q -sl $control` )
  2634.             {
  2635.                 for ( $j = 0; $j < $dataCount; $j++ )
  2636.                 {
  2637.                     $control = $layout + "|qccText" + $i + $j;
  2638.                     $value = `text -q -l $control`;
  2639.                     bdeQcSetValue( $parent, $j, $value );
  2640.                 }
  2641.             }
  2642.         }
  2643.     }
  2644.     // Discrete range checks the use min and use max fields
  2645.     // and the numeric fields, and the value fields are filled 
  2646.     // with text which looks like
  2647.     // [x,y], where x/y are either the min/max values or * if
  2648.     // useMin/Max is turned off
  2649.     else if ( $selectType == $bdeDiscreteRangeName )
  2650.     {
  2651.         string $layout = $tab + "|" + $thisLayout + "|drLayout";
  2652.         for ( $i = 0; $i < $dataCount; $i++ )
  2653.         {
  2654.             string $row = $layout + "|rowLayout" + $i;
  2655.             $value = "[";
  2656.             $control = $row + "|useMin";
  2657.             $dataType = getDataType( $bdt, $i );
  2658.             if ( `checkBox -q -v $control` )
  2659.             {
  2660.                 $control = $row + "|minVal";
  2661.                 if ( $dataType == "int" )
  2662.                 {
  2663.                     $value += `intField -q -v $control`;
  2664.                     intField -e -en true $control;
  2665.                 }
  2666.                 else
  2667.                 {
  2668.                     $value += `floatField -q -v $control`;
  2669.                     floatField -e -en true $control;
  2670.                 }
  2671.             }
  2672.             else
  2673.             {
  2674.                 $control = $row + "|minVal";
  2675.                 if ( $dataType == "int" )
  2676.                     intField -e -en false $control;
  2677.                 else
  2678.                     floatField -e -en false $control;
  2679.                 $value += "*";
  2680.             }
  2681.             $value += ",";
  2682.             $control = $row + "|useMax";
  2683.             if ( `checkBox -q -v $control` )
  2684.             {
  2685.                 $control = $row + "|maxVal";
  2686.                 if ( $dataType == "int" )
  2687.                 {
  2688.                     $value += `intField -q -v $control`;
  2689.                     intField -e -en true $control;
  2690.                 }
  2691.                 else
  2692.                 {
  2693.                     $value += `floatField -q -v $control`;
  2694.                     floatField -e -en true $control;
  2695.                 }
  2696.             }
  2697.             else
  2698.             {
  2699.                 $control = $row + "|maxVal";
  2700.                 if ( $dataType == "int" )
  2701.                     intField -e -en false $control;
  2702.                 else
  2703.                     floatField -e -en false $control;
  2704.                 $value += "*";
  2705.             }
  2706.             $value += "]";
  2707.             bdeQcSetValue( $parent, $i, $value );
  2708.         }
  2709.     }
  2710.     // Hex values check what setting is selected, and prepends
  2711.     // the appropriate &* string to the value, followed by the 
  2712.     // resulting | of all the selected presets.
  2713.     else if ( $selectType == $bdeHexValName )
  2714.     {
  2715.         string $layout = $tab + "|" + $thisLayout + "|uLayout";
  2716.         $control = $layout + "|hexTypeMenu";
  2717.         string $uType = `optionMenu -q -v $control`;
  2718.         switch( $uType )
  2719.         {
  2720.         case "Set":
  2721.             $value = "&| ";
  2722.             break;
  2723.         case "NotSet":
  2724.             $value = "&~ ";
  2725.             break;
  2726.         case "Equal":
  2727.             $value = "&= ";
  2728.             break;
  2729.         }
  2730.                 
  2731.         string $dataValue[];
  2732.         for ( $i = 0; $i < $dataCount; $i++ )
  2733.             $dataValue[$i] = "0x0000";
  2734.  
  2735.         string $dataLayout = $layout + "|uDataLayout";
  2736.         $numPresets = getPresetCount( $bdt );
  2737.         for ( $i = 0; $i < $numPresets; $i++ )
  2738.         {            
  2739.             $preset = getPresetName( $bdt, $i );
  2740.             $control = $dataLayout + "|qccIndicator" + $i;
  2741.             if ( `checkBox -q -v $control` )
  2742.             {
  2743.                 for ( $j = 0; $j < $dataCount; $j++ )
  2744.                 {
  2745.                     string $attr = getLongName( $bdt, $j );
  2746.                     string $value = getPresetVal( $bdt, $i, $attr );
  2747.                     $control = $dataLayout + "|qccText" + $i + $j;
  2748.                     string $dataString = `text -q -l $control`;
  2749.                     $dataValue[$j] = `orHexString $dataValue[$j] $dataString`;
  2750.                 }
  2751.             }
  2752.         }
  2753.         for ( $i = 0; $i < $dataCount; $i++ )
  2754.         {
  2755.             string $newVal = $value + $dataValue[$i];
  2756.             bdeQcSetValue( $parent, $i, $newVal );
  2757.         }
  2758.     }
  2759.     // For continuous types, only a "%" is entered in the
  2760.     // value fields, and the min and max colors and values are
  2761.     // checked on the query/color action.
  2762.     // The min and max value fields are set here according to
  2763.     // how the data is set up (with the ranges if they are set,
  2764.     // otherwise [0,1] for double data, [0,100] for int data.
  2765.     else if ( $selectType == $bdeContinuousName )
  2766.     {
  2767.         float $min, $max;
  2768.         for ( $i = 0; $i < $dataCount; $i++ )
  2769.         {
  2770.             string $layout = $tab + "|" + $thisLayout + "|cLayout" + $i;
  2771.             bdeQcSetValue( $parent, $i, "%" );
  2772.             string $attr = getLongName( $bdt, $i );
  2773.             $dataType = getDataType( $bdt, $i );
  2774.             $ranged = getRanged( $bdt, $attr );
  2775.             if ( $ranged )
  2776.             {
  2777.                 $min = getMinVal( $bdt, $attr );
  2778.                 $max = getMaxVal( $bdt, $attr );
  2779.             }
  2780.             else
  2781.             {
  2782.                 $min = 0;
  2783.                 if ( $dataType == "int" )
  2784.                     $max = 100;
  2785.                 else
  2786.                     $max = 1;
  2787.             }
  2788.             $minControl = $layout + "|minValue";
  2789.             $maxControl = $layout + "|maxValue";
  2790.             if ( $dataType == "int" )
  2791.             {
  2792.                 intField -e -v $min $minControl;
  2793.                 intField -e -v $max $maxControl;
  2794.             }
  2795.             else
  2796.             {
  2797.                 floatField -e -v $min $minControl;
  2798.                 floatField -e -v $max $maxControl;
  2799.             }
  2800.         }
  2801.     }
  2802.     // As color simply puts an "@" into all the fields,
  2803.     // and the data itself is then used for color actions.
  2804.     else if ( $selectType == $bdeAsColorName)
  2805.     {
  2806.         for ( $i = 0; $i < $dataCount; $i++ )
  2807.         {
  2808.             bdeQcSetValue( $parent, $i, "@" );
  2809.         }
  2810.     }
  2811. }
  2812.  
  2813. // This clears out all of the 'value chooser' UI for the
  2814. // given Qc row.
  2815. global proc bdeQcCDeleteTabs( string $parent )
  2816. {
  2817.     global string        $bdeDiscreteValName;
  2818.     global string        $bdeDiscreteRangeName;
  2819.     global string        $bdeHexValName;
  2820.     global string        $bdeContinuousName;
  2821.     global string        $bdeAsColorName;
  2822.  
  2823.     string $frame = $parent + "|valueLayout";
  2824.     string $layout = $frame + "|valueForm|valueChooser";
  2825.     frameLayout -e -cl true $frame;
  2826.  
  2827.     string $names[] = { $bdeDiscreteValName,
  2828.         $bdeDiscreteRangeName, 
  2829.         $bdeHexValName,
  2830.         $bdeContinuousName,
  2831.         $bdeAsColorName };
  2832.  
  2833.     for ( $name in $names )
  2834.     {        
  2835.         string $tab = bdeQcCGetTab( $name );
  2836.         string $thisLayout = $layout + "|" + $tab;
  2837.         if ( `columnLayout -q -ex $thisLayout` )
  2838.         {
  2839.             deleteUI -lay $tab;
  2840.         }
  2841.     }
  2842. }
  2843.  
  2844. // This function gets called when the value enable is turned
  2845. // on or when the value chooser type optionMenu changes
  2846. // If $setValues is true (1), the value fields will get set
  2847. // with the state of the controls
  2848. global proc bdeQcOpenValueTab( string $parent, int $setValues )
  2849. {
  2850.     global string        $bdeDiscreteValName;
  2851.     global string        $bdeDiscreteRangeName;
  2852.     global string        $bdeHexValName;
  2853.     global string        $bdeContinuousName;
  2854.     global string        $bdeAsColorName;
  2855.  
  2856.     string $mainLine = $parent + "|mainLine";
  2857.     string $form = $parent + "|valueLayout|valueForm";
  2858.     string $tab = $form + "|valueChooser";
  2859.     string $om = $form + "|valueTypeLayout|valueType";    
  2860.  
  2861.     string $selectType = `optionMenu -q -v $om`;
  2862.     string $desiredTab = bdeQcCGetTab( $selectType );
  2863.  
  2864.     bdeQcDoColorSwap( $parent );
  2865.  
  2866.     string $children[] = `tabLayout -q -ca $tab`;
  2867.     for ( $child in $children )
  2868.     {
  2869.         if ( $child == $desiredTab )
  2870.         {
  2871.             tabLayout -e -st $child $tab;
  2872.             bdeSetQcValues( $parent );
  2873.             return;
  2874.         }
  2875.     }
  2876.  
  2877.     string $bdt = getQcSelectedBdt( $parent );
  2878.     if ( $bdt == "" )
  2879.         return;
  2880.  
  2881.     int $dataCount = getDataCount( $bdt );
  2882.     int $numTags;
  2883.  
  2884.     string $changeCommand = "bdeSetQcValues \"" + $parent + "\"";
  2885.  
  2886.     setParent $tab;
  2887.  
  2888.     columnLayout $desiredTab;
  2889.  
  2890.     // Create a set of radioButtons for the presets, together with 
  2891.     // the name of the presets and the values.
  2892.     // For hex data, the 'hex' option should be used.
  2893.     if ( $selectType == $bdeDiscreteValName )
  2894.     {
  2895.         string $row = `rowColumnLayout -nc 2 dvLayout`;
  2896.             $control = $row + "|radioCollection";
  2897.             radioCollection $control;
  2898.             radioButton -h 1 -vis false qccNoIndicator;
  2899.             separator -h 1 -st "none";
  2900.             $numPresets = getPresetCount( $bdt );
  2901.             for ( $i = 0; $i < $numPresets; $i++ )
  2902.             {
  2903.                 $preset = getPresetName( $bdt, $i);
  2904.                 $control = "qccIndicator" + $i;
  2905.                 radioButton -l $preset -cc $changeCommand $control;
  2906.                 for ( $j = 0; $j < $dataCount; $j++ )
  2907.                 {
  2908.                     string $attr = getLongName( $bdt, $j );
  2909.                     if ( $j != 0 )
  2910.                         separator -st "none";
  2911.                     string $value = getPresetVal( $bdt, $i, $attr );
  2912.                     $control = "qccText" + $i + $j;
  2913.                     text -l $value $control;
  2914.                 }
  2915.             }
  2916.         setParent ..;
  2917.     }
  2918.     // Discrete range creates a 'useMin' checkbox, a min numeric field,
  2919.     // a max numeric field, and a useMax checkbox for each of the
  2920.     // attrs for the selected blind data template (each attr can be
  2921.     // range-queried/colored separately)
  2922.     else if ( $selectType == $bdeDiscreteRangeName )
  2923.     {
  2924.         columnLayout -adj true drLayout;
  2925.             for ( $i = 0; $i < $dataCount; $i++ )
  2926.             {
  2927.                 string $name = getLongName( $bdt, $i );
  2928.                 text -l $name;
  2929.                 $layout = "rowLayout" + $i;
  2930.                 rowLayout -nc 5
  2931.                     -cw 1 25
  2932.                     -cw 2 75
  2933.                     -cw 3 85
  2934.                     -cw 4 75
  2935.                     -cw 5 25 $layout;
  2936.  
  2937.                     checkBox -l "" -v 1 -cc $changeCommand useMin;
  2938.                     
  2939.                     float $min, $max;
  2940.                     $dataType = getDataType( $bdt, $i );
  2941.                     $ranged = getRanged( $bdt, $name );
  2942.                     if ( $ranged )
  2943.                     {
  2944.                         $min = getMinVal( $bdt, $name );
  2945.                         $max = getMaxVal( $bdt, $name );
  2946.                     }
  2947.                     else 
  2948.                     {
  2949.                         $min = 0;
  2950.                         if ( $dataType == "int" )
  2951.                             $max = 100;
  2952.                         else
  2953.                             $max = 1;
  2954.                     }
  2955.  
  2956.                     if ( $dataType == "int" )
  2957.                         intField -w 70 -v $min -cc $changeCommand minVal;                        
  2958.                     else
  2959.                         floatField -w 70 -v $min -cc $changeCommand minVal;
  2960.  
  2961.                     text -l "<=  Value  <=";
  2962.                     // I was going to make the </<= a drop down so open ranges
  2963.                     // could be queried as well as closed (0,1) vs [0,1], but
  2964.                     // this proved to be more work than it was deemed worth
  2965. //                    text -w 20 -l "<=";
  2966. //                    optionMenu -cc $changeCommand minOM;
  2967. //                        menuItem -l "<=";
  2968. //                        menuItem -l "<";
  2969.  
  2970. //                    text -w 40 -l "Value";
  2971.  
  2972. //                    text -w 20 -l "<=";
  2973. //                    optionMenu -cc $changeCommand maxOM;
  2974. //                        menuItem -l "<=";
  2975. //                        menuItem -l "<";
  2976.  
  2977.                     if ( $dataType == "int" )
  2978.                     {
  2979.                         intField -w 70 -v $max -cc $changeCommand maxVal;
  2980.                     }
  2981.                     else
  2982.                     {
  2983.                         floatField -w 70 -v $max -cc $changeCommand maxVal;
  2984.                     }
  2985.  
  2986.                     checkBox -l "" -v 1 -cc $changeCommand useMax;
  2987.                 setParent ..;
  2988.             }
  2989.         setParent ..;
  2990.     }
  2991.     // Hex layout has an optionMenu for the 'Compare type' as well as
  2992.     // checkboxes for each of the presets.
  2993.     else if ( $selectType == $bdeHexValName )
  2994.     {
  2995.         columnLayout uLayout;
  2996.             optionMenu -l "Compare type" -cc $changeCommand hexTypeMenu;
  2997.                 menuItem "Set";
  2998.                 menuItem "NotSet";
  2999.                 menuItem "Equal";
  3000.  
  3001.             separator -h 10 -st "none";
  3002.  
  3003.             rowColumnLayout -nc 2 uDataLayout;
  3004.                 
  3005.                 $numPresets = getPresetCount( $bdt );
  3006.                 for ( $i = 0; $i < $numPresets; $i++ )
  3007.                 {
  3008.                     $preset = getPresetName( $bdt, $i );
  3009.                     $control = "qccIndicator" + $i;
  3010.                     checkBox -l $preset -cc $changeCommand $control;
  3011.                     for ( $j = 0; $j < $dataCount; $j++ )
  3012.                     {
  3013.                         string $name = getLongName( $bdt, $j );
  3014.                         if ( $j != 0 )
  3015.                             separator -st "none";
  3016.                         string $value = getPresetVal( $bdt, $i, $name );
  3017.                         $control = "qccText" + $i + $j;
  3018.                         text -l $value $control;
  3019.                     }
  3020.                 }
  3021.             setParent ..;
  3022.         setParent ..;
  3023.     }
  3024.     // For each of the attributes a min color slider, min numeric field,
  3025.     // max color slider, and max numeric field are created.
  3026.     // If there is only one attribute, the min color defaults to a dark gray
  3027.     // (i found with black the low end values all looked too close together)
  3028.     // and the max color defaults to white. If there are more, the max color for
  3029.     // the first is red, the max for the second is green, and the max for the 
  3030.     // third is blue. So you can track the different attrs on different color
  3031.     // axes. This probably won't make much sense for most cases, but you never
  3032.     // know (and it made sense programmatically to do it this way...)
  3033.     else if ( $selectType == $bdeContinuousName )
  3034.     {
  3035.         string $dataType;
  3036.         float $maxR[] = { 1, 0, 0 };
  3037.         float $maxG[] = { 0, 1, 0 };
  3038.         float $maxB[] = { 0, 0, 1 };
  3039.         for ( $i = 0; $i < $dataCount; $i++ )
  3040.         {
  3041.             $dataType = getDataType( $bdt, $i );
  3042.             $name = getLongName( $bdt, $i );
  3043.             text -l $name;
  3044.             $control = "cLayout" + $i;
  3045.             rowColumnLayout -ut bdeQcColorTemplate $control;
  3046.                 text -l "Min";
  3047.                 colorSliderGrp -rgb .25 .25 .25 minColor;
  3048.                 if ( $dataType == "int" )
  3049.                     intField minValue;
  3050.                 else
  3051.                     floatField minValue;
  3052.  
  3053.                 text -l "Max";
  3054.                 if ( $dataCount == 1 )
  3055.                     colorSliderGrp -rgb 1 1 1 maxColor;
  3056.                 else
  3057.                     colorSliderGrp -rgb $maxR[$i] $maxG[$i] $maxB[$i] maxColor;
  3058.                 if ( $dataType == "int" )
  3059.                     intField maxValue;
  3060.                 else
  3061.                     floatField maxValue;
  3062.             setParent ..;
  3063.  
  3064.             if ( $i != $dataCount-1 )
  3065.                 separator -w 400 -h 8 -st "in";
  3066.         }
  3067.         setParent ..;
  3068.     }
  3069.     // We're using the blind data itself as the criterion, so there's
  3070.     // nothing to do for asColor.
  3071.     else if ( $selectType == $bdeAsColorName)
  3072.     {
  3073.     }
  3074.  
  3075.     if ( $setValues )
  3076.         bdeSetQcValues( $parent );
  3077.  
  3078.     // Select the desired tab. The valueChooser is a tabLayout with
  3079.     // invisible tabs, so we can switch between different value chooser
  3080.     // types without rebuilding the layouts if they've been built already,
  3081.     // and we also keep the values set up by the user for the old layouts.
  3082.     tabLayout -e -st $desiredTab $tab;
  3083. }
  3084.  
  3085. // Create the valueChooser frame and try to guess which chooser type they'd
  3086. // want to use based on how the data for this template looks.
  3087. global proc bdeQcOpenValueChooser( string $parent )
  3088. {
  3089.     global string        $bdeDiscreteValName;
  3090.     global string        $bdeDiscreteRangeName;
  3091.     global string        $bdeHexValName;
  3092.     global string        $bdeContinuousName;
  3093.     global string        $bdeAsColorName;
  3094.  
  3095.     string $mainLine = $parent + "|mainLine";
  3096.     string $frame = $parent + "|valueLayout";
  3097.     string $om = $frame + "|valueForm|valueTypeLayout|valueType";
  3098.  
  3099.     string $control = $mainLine + "|valueEnable";
  3100.     if ( !`checkBox -q -v $control` )
  3101.     {
  3102.         frameLayout -e -cl true -lv false -bv false $frame;
  3103.         return;
  3104.     }
  3105.  
  3106.     string $bdt = getQcSelectedBdt( $parent );
  3107.     if ( $bdt == "" )
  3108.     {
  3109.         frameLayout -e -cl true -lv false -bf false $frame;
  3110.         return;
  3111.     }
  3112.     string $dataType = getDataType( $bdt, 0 );
  3113.  
  3114.     // If first data type is one of these, really only discrete val makes sense
  3115.     if ( $dataType == "string" || $dataType == "binary" || $dataType == "boolean" )
  3116.     {
  3117.         optionMenu -e -v $bdeDiscreteValName $om;
  3118.     }
  3119.     else if ( $dataType == "hex" )
  3120.     {
  3121.         optionMenu -e -v $bdeHexValName $om;
  3122.     }
  3123.     else
  3124.     {
  3125.         // We've got numeric data. If there's no free set, it's probably
  3126.         // an enum type, so we give them discrete val with it's presets.
  3127.         // Otherwise, we give them discrete range if the data's ranged,
  3128.         // and discrete val if not.
  3129.         // It's not hard for the user to change this, but it's also not
  3130.         // hard to change this script so that the initial behaviour is 
  3131.         // different.
  3132.         int $freeSet = getFreeSet( $bdt );
  3133.         if ( !$freeSet )
  3134.         {
  3135.             optionMenu -e -v $bdeDiscreteValName $om;
  3136.         }
  3137.         else
  3138.         {
  3139.             $name = getLongName( $bdt, 0 );
  3140.             if ( getRanged( $bdt, $name ) )
  3141.             {
  3142.                 optionMenu -e -v $bdeContinuousName $om;
  3143.             }
  3144.             else
  3145.             {
  3146.                 optionMenu -e -v $bdeDiscreteValName $om;
  3147.             }
  3148.         }
  3149.     }
  3150.  
  3151.     // Set the values fields, etc.
  3152.     bdeQcOpenValueTab( $parent, 1 );
  3153.  
  3154.     // Open it up.
  3155.     frameLayout -e -bv true -cl false -lv true $frame;
  3156. }
  3157.  
  3158. // This gets called when the type is changed for the given Qc row.
  3159. // It adds the (initially almost empty) chooser layout. After this
  3160. // call, the valueTypeLayout just has the optionMenu for selecting the
  3161. // value type and the invisible saveColor. The rest of the stuff gets
  3162. // added if and when the user decides he's going to use the value data.
  3163. // It restricts what value types are available for the selected type
  3164. // based on the data in that template.
  3165. // Edit this function if you need to get at some of the value types
  3166. // for your particular data and they aren't available.
  3167. global proc bdeQcSetSelectOptions( string $parent )
  3168. {
  3169.     global string        $bdeDiscreteValName;
  3170.     global string        $bdeDiscreteRangeName;
  3171.     global string        $bdeHexValName;
  3172.     global string        $bdeContinuousName;
  3173.     global string        $bdeAsColorName;
  3174.  
  3175.     string $bdt = getQcSelectedBdt( $parent );
  3176.     if ( $bdt == "" )
  3177.         return;
  3178.  
  3179.     int $dataCount = getDataCount( $bdt );
  3180.     string $dataType = getDataType( $bdt, 0 );
  3181.  
  3182.     string $form = $parent + "|valueLayout|valueForm";
  3183.  
  3184.     setParent $form;
  3185.  
  3186.     string $layout = $form + "|valueTypeLayout";
  3187.     if ( `columnLayout -q -ex $layout` )
  3188.         deleteUI -lay $layout;
  3189.  
  3190.     columnLayout -adj true valueTypeLayout;
  3191.         optionMenu -cc ( "bdeQcOpenValueTab ( \"" + $parent + "\", 1 )" ) valueType;
  3192.         // This is the only thing a user can select for these data types.
  3193.         if ( $dataType == "string" || $dataType == "binary" || $dataType == "boolean" )
  3194.         {
  3195.             menuItem $bdeDiscreteValName;
  3196.         }
  3197.         // Discrete range doesn't make a lot of sense for hex data, but we'll 
  3198.         // let them choose it if they want
  3199.         else if ( $dataType == "hex" )
  3200.         {
  3201.             menuItem $bdeDiscreteValName;
  3202.             menuItem $bdeDiscreteRangeName;
  3203.             menuItem $bdeHexValName;
  3204.         }
  3205.         else
  3206.         {
  3207.             menuItem $bdeDiscreteValName;
  3208.             menuItem $bdeDiscreteRangeName;
  3209.             // Probably only makes sense if $dataCount == 1, but
  3210.             // we'll let them try to make some sense of the 2-3 axis
  3211.             // color data if they want
  3212.             if ( $dataCount <= 3 )
  3213.                 menuItem $bdeContinuousName;
  3214.             // If there are three fields, as color maybe makes sense
  3215.             // If they're not floats ranged [0,1] other modifications 
  3216.             // will have to be made, but not hard to convert from int
  3217.             // [0,255] fields to float [0,1] fields when the color action
  3218.             // happens.
  3219.             if ( $dataCount == 3 )
  3220.                 menuItem $bdeAsColorName;
  3221.         }
  3222.         // Create the invisible saveColor canvas and initialize it
  3223.         // with the color from the main canvas.
  3224.         $control = $parent + "|mainLine|canvas";
  3225.         float $col[] = `canvas -query -rgbValue $control`;
  3226.         canvas -visible false -height 1 -rgbValue $col[0] $col[1] $col[2] saveColor;
  3227.     setParent ..;
  3228.  
  3229.     // Make the form look right.
  3230.     formLayout -e
  3231.         -af valueTypeLayout "top" 5
  3232.         -af valueTypeLayout "left" 5
  3233.         -ac valueTypeLayout "right" 5 valueChooser
  3234.         -an valueTypeLayout "bottom"
  3235.  
  3236.         -af valueChooser "top" 0
  3237.         -af valueChooser "right" 0
  3238.         -an valueChooser "left"
  3239.         -af valueChooser "bottom" 0
  3240.         $form;
  3241. }
  3242.  
  3243. // Called when the type for a particular qc row changes.
  3244. // This can be done either through popup menu on the type field,
  3245. // typing in the type field, or when the editor is first opened or
  3246. // torn off (and saved prefs fill in the types)
  3247. global proc bdeQcChangeType( string $parent )
  3248. {
  3249.     string $mainLine = $parent + "|mainLine";
  3250.     string $layoutName;
  3251.  
  3252.     string $bdt = getQcSelectedBdt( $parent );
  3253.  
  3254.     // Delete the multi list (which may not be full, but that's ok too)
  3255.     // We'll rebuild it later if value enable is checked.
  3256.     $layoutName = $parent + "|multiList";
  3257.     frameLayout -e -cl true $layoutName;
  3258.     bdeQcDeleteMultiList( $layoutName );
  3259.  
  3260.     // These may not exist either, but better chuck them out if they do
  3261.     // (or there'll be lots of them when type keeps changing)
  3262.     bdeQcCDeleteTabs( $parent );    
  3263.  
  3264.     // No type for this one -- disable or blank out everything
  3265.     if ( $bdt == "" )
  3266.     {
  3267.         $controlName = $mainLine + "|type";
  3268.         textField -e -tx "" $controlName;
  3269.         $controlName = $mainLine + "|enable";
  3270.         checkBox -e -v 0 $controlName;
  3271.         $controlName = $mainLine + "|valueEnable";
  3272.         checkBox -e -v 0 -en false $controlName;
  3273.         $controlName = $mainLine + "|longName";
  3274.         text -e -l "" $controlName;
  3275.         // We only have to blank out the first value as the multi's been nixed
  3276.         bdeQcSetValue( $parent, 0, "" );
  3277.     }
  3278.     else
  3279.     {
  3280.         // Turn on the row enable (since they've selected it they probably
  3281.         // want to use it)
  3282.         $controlName = $mainLine + "|enable";
  3283.         checkBox -e -v 1 $controlName;
  3284.         // Turn off the value enable (they've just selected this one, so
  3285.         // we'll assume to start that they want to do a binary on it)
  3286.         $controlName = $mainLine + "|valueEnable";
  3287.         checkBox -e -en true -v 0 $controlName;
  3288.         // Blank the name (it's not what it was, maybe)
  3289.         $controlName = $mainLine + "|longName";
  3290.         text -e -l "" $controlName;
  3291.         // Blank all the values
  3292.         int $dataCount = getDataCount ( $bdt );
  3293.         for ( $i = 0; $i < $dataCount; $i++ )
  3294.             bdeQcSetValue( $parent, $i, "" );
  3295.  
  3296.         // Do some setup for the future
  3297.         bdeQcSetSelectOptions( $parent );
  3298.     }
  3299.  
  3300.     // Not sure that this call is necessary...
  3301.     bdeQcOpenValueChooser( $parent );
  3302.  
  3303.     // Save colors
  3304.     bdeQcDoColorSwap( $parent );
  3305. }
  3306.  
  3307. // Called when the user changes the 'value Enable' checkbox.
  3308. global proc bdeQcChangeValueEnable( string $parent )
  3309. {
  3310.     string $mainLine = $parent + "|mainLine";
  3311.     string $controlName = $mainLine + "|valueEnable";
  3312.     int $enabled = `checkBox -q -v $controlName`;    
  3313.  
  3314.     // They turned it on. So we fill in the name,
  3315.     // build the multi and open it up.
  3316.     if ( $enabled )
  3317.     {
  3318.         string $bdt = getQcSelectedBdt( $parent );
  3319.         if ( $bdt == "" )
  3320.         {
  3321.             error( "bdeQcChangeValueEnable" );
  3322.             return;
  3323.         }
  3324.         
  3325.         $controlName = $mainLine + "|longName";
  3326.         string $longName = getLongName( $bdt, 0 );
  3327.         text -e -l $longName $controlName;
  3328.  
  3329.         int $dataCount = getDataCount( $bdt );
  3330.         if ( $dataCount > 1 )
  3331.         {
  3332.             bdeQcBuildMultiList( $parent );
  3333.             $layoutName = $parent + "|multiList";
  3334.             frameLayout -e -cl false $layoutName;
  3335.         }
  3336.     }
  3337.     // Turned it off. Blank the name and values,
  3338.     // close the multi.
  3339.     else
  3340.     {
  3341.         $controlName = $mainLine + "|longName";
  3342.         text -e -l "" $controlName;
  3343.  
  3344.         $controlName = $mainLine + "|value";
  3345.         textField -e -tx "" $controlName;
  3346.  
  3347.         $layoutName = $parent + "|multiList";
  3348.         frameLayout -e -cl true $layoutName;
  3349.     }
  3350.  
  3351.     bdeQcOpenValueChooser( $parent );
  3352.     bdeQcDoColorSwap( $parent );
  3353. }
  3354.  
  3355. // Called automatically when the type popup is used for a 
  3356. // query color row. Fills the typeField and then calls bdeQcChangeType
  3357. // which blanks out other stuff, etc.
  3358. global proc bdeChangedQcPopup( string $layout, int $id )
  3359. {
  3360.     string $bdt = getTemplateNameFromId( $id );
  3361.     if ( $bdt == "" )
  3362.         return;
  3363.     string $tag = getTag( $bdt );
  3364.     string $control = $layout + "|mainLine|type";
  3365.  
  3366.     if ( $tag != "" )
  3367.         textField -e -tx $tag $control;
  3368.     else
  3369.         textField -e -tx $id $control;
  3370.  
  3371.     bdeQcChangeType( $layout );
  3372. }
  3373.  
  3374. // Create the type popup for the given qc row
  3375. // based on what templates exist in the scene.
  3376. global proc bdeAddQcPopup( string $layout )
  3377. {
  3378.     string $command;
  3379.     // Bug 150384 check exact type so we don't get subd blind data
  3380.     string $nodes[] = `ls -exactType blindDataTemplate`;
  3381.     string $blindDataTags[];
  3382.     int $blindDataIds[];
  3383.     string $menuItem;
  3384.  
  3385.     string $control = $layout + "|mainLine|type";
  3386.     popupMenu -aob false -mm false -parent $control typePopup;
  3387.  
  3388.     for ( $i = 0; $i < size( $nodes ); $i++ )
  3389.     {
  3390.         $blindDataTags[$i] = getTag( $nodes[$i] );
  3391.         $blindDataIds[$i] = getId( $nodes[$i] );
  3392.         if ( $blindDataTags[$i] != "" )
  3393.             $menuItem = $blindDataTags[$i];
  3394.         else
  3395.             $menuItem = $blindDataIds[$i];
  3396.  
  3397.         $command = "bdeChangedQcPopup ( \"" + $layout + "\", " + $blindDataIds[$i] + " )";
  3398.         menuItem -c $command -l $menuItem;
  3399.     }
  3400. }
  3401.  
  3402. // If the scene changes, we rebuild all of the popups to reflect
  3403. // what's in the scene.
  3404. global proc bdeRebuildPopups()
  3405. {
  3406.     global string $bdeQueryColorLayout;
  3407.  
  3408.     if ( `columnLayout -q -ex $bdeQueryColorLayout` )
  3409.     {
  3410.         string $children[] = `columnLayout -q -ca $bdeQueryColorLayout`;
  3411.         for ( $child in $children )
  3412.         {
  3413.             $layout = $bdeQueryColorLayout + "|" + $child;
  3414.             $control = $layout + "|mainLine|type|typePopup";
  3415.             if ( `popupMenu -q -ex $control` )
  3416.                 deleteUI $control;
  3417.             bdeAddQcPopup( $layout );
  3418.         }
  3419.     }
  3420. }
  3421.  
  3422. // Build and add a row to the query/color layout.
  3423. global proc string bdeAddQueryColorRow( string $parent )
  3424. {
  3425.     setParent $parent;    
  3426.  
  3427.     // Bug 150384 check exact type so we don't get subd blind data
  3428.     string $nodes[] = `ls -exactType blindDataTemplate`;
  3429.     string $blindDataTags[];
  3430.     int $blindDataIds[];
  3431.     string $menuItem[];
  3432.     for ( $i = 0; $i < size( $nodes ); $i++ )
  3433.     {
  3434.         $blindDataTags[$i] = getTag( $nodes[$i] );
  3435.         $blindDataIds[$i] = getId( $nodes[$i] );
  3436.         if ( $blindDataTags[$i] != "" )
  3437.             $menuItem[$i] = $blindDataTags[$i];
  3438.         else
  3439.             $menuItem[$i] = $blindDataIds[$i];
  3440.     }
  3441.  
  3442.     // This $layout var is how we reference this row.
  3443.     // All qc controls are children/grandchildren/etc. of
  3444.     // this columnLayout.
  3445.     string $layout = `columnLayout`;
  3446.     // mainLine has the stuff you initially see
  3447.     // (enable box, type field, value enable box, type name, 
  3448.     //  value field, delete button)
  3449.         rowLayout -ut bdeQcMainLineTemplate mainLine;
  3450.             checkBox -w 20 -l "" enable;
  3451.             textField -w 100 -en true 
  3452.                 -cc ( "bdeQcChangeType (\"" + $layout + "\")" ) type;
  3453.                 bdeAddQcPopup( $layout );
  3454.             checkBox -w 20 -l "" -en false
  3455.                 -cc ( "bdeQcChangeValueEnable \"" + $layout + "\"" ) valueEnable;
  3456.             text -w 60 -l "" longName;
  3457.             textField -w 90 -en true
  3458.                 -cc ( "bdeQcChangedValue \"" + $layout + "\"" ) value;
  3459.             separator -st "none";
  3460.             float $c[] = `bdeGetUniqueColor`;
  3461.             canvas -rgbValue $c[0] $c[1] $c[2]
  3462.                 -pc ( "bdeChangeCanvas \"" + $layout + "\"" ) 
  3463.                 -w 70 -h 25 canvas;
  3464.             button -l "Delete" -c ( "bdeQcDeleteRow \"" + $layout + "\"" );
  3465.         setParent ..;
  3466.  
  3467.         // This one's for multi's
  3468.         // It's empty initially, gets children if necessary
  3469.         frameLayout -cll true -cl true -lv false -bv false multiList;
  3470.         setParent ..;
  3471.  
  3472.         // For space only
  3473.         separator -h 5 -style "none";
  3474.  
  3475.         // The value layout, initially mostly empty.
  3476.         frameLayout -cll true -cl true -lv false -bv false 
  3477.             -l "Select value" valueLayout;
  3478.             string $form = `formLayout -w 300 valueForm`;
  3479.             // I had to set the dimensions manually because on IRIX
  3480.             // switching the tabs to a larger one didn't expand the tab.
  3481.             // It's scrollable, so if it goes bigger than the fairly
  3482.             // big dimensions, you can scroll to the rest of the values.
  3483.                 tabLayout -iv false -tv false -scr true -cr false -w 350 -h 200 valueChooser;
  3484.                 setParent ..;
  3485.             setParent ..;            
  3486.         setParent ..;
  3487.  
  3488.         separator -h 5 -style "none";
  3489.  
  3490.     setParent ..;
  3491.     
  3492.     return $layout;
  3493. }
  3494.  
  3495. // Gets an empty row for the main qc layout, or, if none exists,
  3496. // creates a new one.
  3497. // The name of the layout created or found is returned.
  3498. proc string getEmptyQcRow()
  3499. {
  3500.     global string $bdeQueryColorLayout;
  3501.  
  3502.     if ( `columnLayout -q -ex $bdeQueryColorLayout` )
  3503.     {
  3504.         string $children[] = `columnLayout -q -ca $bdeQueryColorLayout`;
  3505.         for ( $child in $children )
  3506.         {
  3507.             $layout = $bdeQueryColorLayout + "|" + $child;
  3508.             $type = getQcType( $layout );
  3509.             if ( $type == "" )
  3510.                 return $layout;
  3511.         }
  3512.     }
  3513.  
  3514.     return bdeAddQueryColorRow( $bdeQueryColorLayout );
  3515. }
  3516.  
  3517. // Delete all the rows and build 5 new ones.
  3518. // This typically gets called on file/new or file/open.
  3519. global proc bdeRebuildQueryColor()
  3520. {
  3521.     global string $bdeQueryColorLayout;
  3522.  
  3523.     if ( `columnLayout -q -ex $bdeQueryColorLayout` )
  3524.     {
  3525.         string $children[] = `columnLayout -q -ca $bdeQueryColorLayout`;
  3526.         for ( $child in $children )
  3527.             deleteUI -lay $child;
  3528.  
  3529.         // INITIAL NUMBER OF ROWS HERE
  3530.         for ( $i = 0; $i < 5; $i++ )
  3531.             bdeAddQueryColorRow( $bdeQueryColorLayout );
  3532.     }
  3533. }
  3534.  
  3535. // Called when you press the 'New' button on the qc tab.
  3536. global proc bdeNewQcRow()
  3537. {
  3538.     global string $bdeQueryColorLayout;
  3539.  
  3540.     bdeAddQueryColorRow( $bdeQueryColorLayout );
  3541. }
  3542.  
  3543. // Called when you press the delete button on the qc row.
  3544. global proc bdeQcDeleteRow( string $layout )
  3545. {
  3546.     deleteUI -lay $layout;
  3547. }
  3548.  
  3549. // This function to determine whether or not the 
  3550. // color/query can work with all of the selected qc rows
  3551. // The numbers don't have internal meaning - they just have
  3552. // to be distinct.
  3553. proc int compatibleMode( int $mode )
  3554. {
  3555.     global int            $bdeBinaryMode;
  3556.     global int            $bdeContinuousMode;
  3557.     global int            $bdeAsColorMode;
  3558.  
  3559.     // Can't use variables in a switch
  3560.     switch ( $mode )
  3561.     {
  3562.     // binary mode
  3563.     case 0:
  3564.         return 0;
  3565.     // Continuous mode
  3566.     case 6:
  3567.         return 2;
  3568.     // as color mode
  3569.     case 7:
  3570.         return 3;
  3571.     // Otherwise the data is discretely ranged or valued.
  3572.     default:
  3573.         return 1;
  3574.     }
  3575. }
  3576.  
  3577. // Look at the value and datatype and determine what mode it is
  3578. proc int parseValueForMode( string $value, string $dataType )
  3579. {
  3580.     global int            $bdeDiscreteValueMode;
  3581.     global int            $bdeDiscreteRangeMode;
  3582.     global int            $bdeHexSetMode;
  3583.     global int            $bdeHexNotSetMode;
  3584.     global int            $bdeHexEqualMode;
  3585.     global int            $bdeContinuousMode;
  3586.     global int            $bdeAsColorMode;
  3587.     
  3588.     string $char = `getChar $value 1`;
  3589.  
  3590.     if ( $dataType == "string" || $dataType == "binary" || $dataType == "boolean" )
  3591.     {
  3592.         return $bdeDiscreteValueMode;
  3593.     }
  3594.  
  3595.     if ( $char == "@" )
  3596.     {
  3597.         return $bdeAsColorMode;
  3598.     }
  3599.     if ( $char == "%" )
  3600.     {
  3601.         return $bdeContinuousMode;
  3602.     }
  3603.     if ( $char == "[" )
  3604.         return $bdeDiscreteRangeMode;
  3605.  
  3606.     if ( $dataType == "hex" )
  3607.     {
  3608.         int $length = `size $value`;
  3609.         string $token = `substring $value 1 2`;
  3610.         string $val = `substring $value 4 $length`;
  3611.         if ( $token == "&|" )
  3612.             return $bdeHexSetMode;
  3613.         else if ( $token == "&~" )
  3614.             return $bdeHexNotSetMode;
  3615.         else if ( $token == "&=" )
  3616.             return $bdeHexEqualMode;
  3617.         else // Default:
  3618.             return $bdeHexEqualMode;
  3619.     }    
  3620.  
  3621.     return $bdeDiscreteValueMode;
  3622. }
  3623.  
  3624. // Given the text value, dataType, and mode, figure out what
  3625. // the actual value is (e.g., if the $value == "&| 0x0010, then
  3626. // 0x0010 is the value we're after, which gets converted to "16")
  3627. proc string parseValueForValue( string $value, string $dataType, int $mode )
  3628. {
  3629.     global int            $bdeDiscreteValueMode;
  3630.     global int            $bdeDiscreteRangeMode;
  3631.     global int            $bdeHexSetMode;
  3632.     global int            $bdeHexNotSetMode;
  3633.     global int            $bdeHexEqualMode;
  3634.     global int            $bdeContinuousMode;
  3635.     global int            $bdeAsColorMode;
  3636.  
  3637.     string $retString;    
  3638.     int $length = `size $value`;
  3639.     string $char = `getChar $value 1`;
  3640.  
  3641.     if ( $dataType == "string" || $dataType == "binary" )
  3642.     {
  3643.         return $value;
  3644.     }
  3645.  
  3646.     if ( $dataType == "hex" )
  3647.     {
  3648.         $retString = "0";
  3649.         for ( $i = 1; $i < $length; $i++ )
  3650.         {
  3651.             $char = `getChar $value $i`;
  3652.             if ( $char == " " || $char == "&" ||
  3653.                  $char == "|" || $char == "~" ||
  3654.                  $char == "=" )
  3655.                  continue;
  3656.  
  3657.             $retString = `substring $value $i $length`;
  3658.             int $val = `hexStringToInt $retString`;
  3659.             $retString = $val;
  3660.             break;            
  3661.         }
  3662.         return $retString;
  3663.     }
  3664.     
  3665.     if ( $dataType == "boolean" )
  3666.     {
  3667.         if ( $char == "0" || $char == "f" || $char == "F" )
  3668.             return "0";
  3669.         else
  3670.             return "1";
  3671.     }
  3672.     
  3673.     if ( $char == "@" )
  3674.         return "";
  3675.     else if ( $char == "%" )
  3676.         return "";
  3677.     else if ( $char == "[" || $char == "(" || $char == "{" )
  3678.         return "";
  3679.     else
  3680.         return $value;
  3681. }
  3682.  
  3683. // Which is either "min" (indicating we're looking for the min value)
  3684. // or something else, indicating max. We assume the $value looks like
  3685. // [x,y], and return appropriate x/y as a string (it might be *)
  3686. proc string parseValueForMinMax( string $value, string $which )
  3687. {
  3688.     string $val;
  3689.     int $length = `size $value` - 1;
  3690.     string $stripped = `substring $value 2 $length`;
  3691.     string $buffer[];
  3692.     tokenize $stripped "," $buffer;
  3693.     if ( $which == "min" )
  3694.         $val = $buffer[0];
  3695.     else
  3696.         $val = $buffer[1];
  3697.  
  3698.     return $val;
  3699. }
  3700.  
  3701. // Convert a list (usually obtained via `ls -sl`) to 
  3702. // the given assocType ("face", "vertex", "object" )
  3703. // Returns as a string array the new list (filtering out
  3704. // duplicates)
  3705. proc string[] convList( string $list[], string $assocType )
  3706. {
  3707.     string $newList[];
  3708.     string $filteredList[];
  3709.     string $convCmd = "polyListComponentConversion";
  3710.     string $convType = "none";
  3711.  
  3712.     // We just get the first element of each string in the given array
  3713.     if ( $assocType == "object" )
  3714.     {
  3715.         string $array[];
  3716.         for ( $selIndex = 0; $selIndex < size($list); $selIndex++ )
  3717.         {
  3718.             $array = getSelectionComp( $list[$selIndex] );
  3719.             $newList[$selIndex] = $array[0];
  3720.         }
  3721.     }
  3722.     else if ( $assocType == "vertex" )
  3723.         $convType = " -tv";
  3724.     else if ( $assocType == "face" )
  3725.         $convType = " -tf";
  3726.     else // Just return the list they passed us
  3727.         return $list;
  3728.     
  3729.     if ( $convType != "none" )
  3730.     {
  3731.         $convCmd += $convType;
  3732.         $newList = `eval $convCmd`;
  3733.     }
  3734.  
  3735.     // Go through our list and filter out any duplicates.
  3736.     string $filteredSel[];
  3737.     for ( $preIndex = 0, $postIndex = 0; $preIndex < size($newList); $preIndex++ )
  3738.     {
  3739.         int $foundIt = 0;
  3740.         for ( $i = 0; $i < size($filteredSel); $i++ )
  3741.         {
  3742.             if ( $filteredSel[$i] == $newList[$preIndex] )
  3743.                 $foundIt = 1;
  3744.         }
  3745.  
  3746.         if ( !$foundIt )
  3747.         {
  3748.             $filteredSel[$postIndex++] = $newList[$preIndex];
  3749.         }
  3750.     }
  3751.  
  3752.     return $filteredSel;
  3753. }
  3754.  
  3755. // Go through the query/color rows and construct the command to
  3756. // do the action. If $doColor is true, the action specified is 'Color',
  3757. // otherwise 'Query'.
  3758. global proc bdeDoQueryColor( int $doColor )
  3759. {
  3760.     global string        $bdeQueryColorLayout;
  3761.     global int            $bdeBinaryMode;
  3762.     global int            $bdeDiscreteRangeMode;
  3763.     global int            $bdeContinuousMode;
  3764.     global int            $bdeAsColorMode;
  3765.  
  3766.     string $parent = $bdeQueryColorLayout;
  3767.  
  3768.     // Only do the action if something's selected
  3769.     // (Action works on selection only - could easily 
  3770.     // change this to work on the whole scene, if desired,
  3771.     // but selection->action is the way maya typically
  3772.     // works).
  3773.     string $selected[] = `ls -sl`;
  3774.     if ( size( $selected ) == 0 )
  3775.         return;
  3776.     
  3777.     string $layout;
  3778.     string $control;
  3779.     string $tag;
  3780.     string $bdt;
  3781.     int $id;
  3782.     int $ids[];
  3783.     int $mode;
  3784.     int $modes[];
  3785.     string $name;
  3786.     string $value;
  3787.     string $values[];
  3788.     string $assocTypes[];
  3789.     string $origSelection[];
  3790.     string $cmd;
  3791.     float $color[];
  3792.     
  3793.     int $k = -1;
  3794.     if ( $doColor )
  3795.     {
  3796.         // 'NoneColor' and 'ClashColor' are common to all of the criterion
  3797.         $cmd = "polyColorBlindData ";
  3798.         $color = `canvas -query -rgbValue bdeNoneColor`;
  3799.         $cmd += " -ncr " + $color[0] + " -ncg " + $color[1] + " -ncb " + $color[2];
  3800.         $color = `canvas -query -rgbValue bdeClashColor`;
  3801.         $cmd += " -ccr " + $color[0] + " -ccg " + $color[1] + " -ccb " + $color[2];        
  3802.     }    
  3803.     else
  3804.         $cmd = "polyColorBlindData -q ";
  3805.  
  3806.     string $children[] = `columnLayout -q -ca $parent`;    
  3807.  
  3808.     // These children are the different rows.
  3809.     for ( $child in $children )
  3810.     {
  3811.         $thisParent = $parent + "|" + $child;
  3812.         $layout = $thisParent + "|mainLine";
  3813.         $control = $layout + "|enable";        
  3814.         
  3815.         // Enable for this line is off, skip this row
  3816.         if ( !`checkBox -q -v $control` )
  3817.             continue;        
  3818.         
  3819.         $bdt = getQcSelectedBdt( $thisParent );
  3820.         if ( $bdt == "" )
  3821.             continue;
  3822.         $id = getId ( $bdt );
  3823.         // Should maybe check if idDefined here...
  3824.  
  3825.         $ids[++$k] = $id;
  3826.         $cmd += " -id " + $id;
  3827.  
  3828.         $assocTypes[$k] = getAssocType( $bdt );
  3829.         if ( $assocTypes[$k] == "" )
  3830.             $assocTypes[$k] = "any";
  3831.  
  3832.         $control = $layout + "|valueEnable";
  3833.  
  3834.         // Have to specify how many attrs we have
  3835.         int $dataCount = getDataCount( $bdt );
  3836.         $cmd += " -num " + $dataCount;
  3837.  
  3838.         // If valueEnable isn't checked, the data is considered 'binary'
  3839.         if ( !`checkBox -q -v $control` )
  3840.         {
  3841.             $modes[$k] = $bdeBinaryMode;
  3842.             $cmd += " -m " + $bdeBinaryMode;
  3843.             for ( $i = 0; $i < $dataCount; $i++ )
  3844.             {
  3845.                 $name = getLongName( $bdt, $i );
  3846.                 $cmd += " -n \"" + $name + "\"";
  3847.             }
  3848.  
  3849.             $control = $layout + "|canvas";
  3850.             $color = `canvas -query -rgbValue $control`;
  3851.             $cmd += " -cr " + $color[0] + " -cg " + $color[1] + " -cb " + $color[2];
  3852.             continue;
  3853.         }
  3854.         
  3855.         for ( $i = 0; $i < $dataCount; $i++ )
  3856.         {
  3857.             $name = getLongName( $bdt, $i );
  3858.             $dataType = getDataType( $bdt, $i );            
  3859.  
  3860.             $value = getQcValue( $thisParent, $i );
  3861.             if ( $i == 0 )
  3862.             {
  3863.                 $mode = parseValueForMode( $value, $dataType );                
  3864.                 $cmd += " -m " + $mode;
  3865.                 $modes[$k] = $mode;
  3866.             }
  3867.         
  3868.             $cmd += " -dt \"" + $dataType + "\"";
  3869.             $cmd += " -n \"" + $name + "\"";            
  3870.  
  3871.             if ( $mode != $bdeContinuousMode && 
  3872.                  $mode != $bdeDiscreteRangeMode &&
  3873.                  $mode != $bdeAsColorMode )
  3874.             {
  3875.                 $value = parseValueForValue( $value, $dataType, $mode );
  3876.                 if ( $value == "" )
  3877.                 {
  3878.                     warning( "No value present for " + $tag + " (id: " + $id
  3879.                         + ") - " + $name );
  3880.                     return;
  3881.                 }
  3882.                 $cmd += " -v \"" + $value + "\"";
  3883.             }
  3884.  
  3885.             if ( $mode == $bdeDiscreteRangeMode )
  3886.             {
  3887.                 string $min = parseValueForMinMax( $value, "min" );
  3888.                 string $max = parseValueForMinMax( $value, "max" );
  3889.                 if ( $min == "*" )
  3890.                     $cmd += " -umn 0";
  3891.                 else
  3892.                 {
  3893.                     $cmd += " -umn 1";
  3894.                     $cmd += " -mnv " + $min;
  3895.                 }
  3896.                 if ( $max == "*" )
  3897.                     $cmd += " -umx 0";
  3898.                 else
  3899.                 {
  3900.                     $cmd += " -umx 1";
  3901.                     $cmd += " -mxv " + $max;
  3902.                 }
  3903.             }
  3904.  
  3905.             if ( $mode == $bdeContinuousMode && $i == 0 )
  3906.             {
  3907.                 $color = `canvas -query -rgbValue bdeOutOfRangeColor`;
  3908.                 // Out of range == belowMin == aboveMax
  3909.                 // Note that it would be very easy to add separate canvases for 
  3910.                 // both the below min and above max colors. Wasn't deemed 
  3911.                 // necessary, and was thought it would clutter things up too 
  3912.                 // much, but if this functionality is desired, search for 
  3913.                 // bdeOutOfRangeColor, and replace it's occurrences with
  3914.                 // bdeBelowMinColor and bdeAboveMaxColor, then set these flags 
  3915.                 // accordingly.
  3916.                 $cmd += " -bmr " + $color[0] + 
  3917.                         " -bmg " + $color[1] + 
  3918.                         " -bmb " + $color[2];
  3919.                 $cmd += " -amr " + $color[0] + 
  3920.                         " -amg " + $color[1] + 
  3921.                         " -amb " + $color[2];
  3922.             }
  3923.  
  3924.             if ( $mode == $bdeContinuousMode )
  3925.             {
  3926.                 string $layout = $thisParent + "|valueLayout|valueForm|"
  3927.                     + "valueChooser|chooserC|";
  3928.                 $layout += "cLayout" + $i;
  3929.  
  3930.                 if ( $doColor )
  3931.                 {
  3932.                     $control = $layout + "|minColor";
  3933.                     $color = `colorSliderGrp -q -rgb $control`;
  3934.                     $cmd += " -mnr " + $color[0] + 
  3935.                             " -mng " + $color[1] + 
  3936.                             " -mnb " + $color[2];
  3937.                     $control = $layout + "|maxColor";
  3938.                     $color = `colorSliderGrp -q -rgb $control`;
  3939.                     $cmd += " -mxr " + $color[0] + 
  3940.                             " -mxg " + $color[1] + 
  3941.                             " -mxb " + $color[2];
  3942.                 }
  3943.             
  3944.                 // Need the min and max values for query mode
  3945.                 $control = $layout + "|minValue";
  3946.                 float $val;
  3947.                 if ( $dataType == "int" )
  3948.                     $val = `intField -q -v $control`;
  3949.                 else
  3950.                     $val = `floatField -q -v $control`;
  3951.                 $cmd += " -mnv " + $val;
  3952.                 $control = $layout + "|maxValue";
  3953.                 if ( $dataType == "int" )
  3954.                     $val = `intField -q -v $control`;
  3955.                 else
  3956.                     $val = `floatField -q -v $control`;
  3957.                 $cmd += " -mxv " + $val;
  3958.             }
  3959.             else
  3960.             {
  3961.                 // All modes other than continuous simply
  3962.                 // give the color of the canvas for this row (except
  3963.                 // for asColor, but extra flags in the cmd don't hurt any...)
  3964.                 if ( $doColor )
  3965.                 {
  3966.                     $control = $layout + "|canvas";
  3967.                     $color = `canvas -query -rgbValue $control`;
  3968.                     $cmd += " -cr " + $color[0] + 
  3969.                             " -cg " + $color[1] + 
  3970.                             " -cb " + $color[2];
  3971.                 }
  3972.             }
  3973.         }                        
  3974.     }
  3975.     $numIds = $k++;
  3976.  
  3977.     int $firstMode = compatibleMode( $modes[0] );
  3978.     string $assocType = $assocTypes[0];
  3979.     if ( $numIds >= 0 )
  3980.     {
  3981.         // Check to see if it makes sense to do the command with the
  3982.         // given types. Some go together (e.g. discreteVal and discreteRange),
  3983.         // some do not (binary and continuous)
  3984.         // Also, we'll look at all of the associationTypes. If they're all
  3985.         // set and the same, we'll convert to that type.
  3986.         for ( $i = 1; $i < $numIds; $i++ )
  3987.         {
  3988.             $assoc = $assocTypes[$i];
  3989.             $mode = compatibleMode( $modes[$i] );
  3990.             if ( $mode != $firstMode )
  3991.             {
  3992.                 warning "Must have compatible modes";
  3993.                 return;
  3994.             }
  3995.             if ( $assoc != $assocType )
  3996.             {
  3997.                 $assocType = "any";
  3998.             }
  3999.         }        
  4000.  
  4001.         // Save this so we can reset it after the action is performed.
  4002.         $origSel = `ls -sl`;
  4003.  
  4004.         // $assocType right now has the _common_ assocType for all of the 
  4005.         // selected rows. If this is set to something, we convert the selection
  4006.         // to this type (and select it).
  4007.         // This may be more than the user wants - in this case, comment out
  4008.         // the eval in the block.
  4009.         if ( $assocType != "any" )
  4010.         {
  4011.             string $newSel[] = convList( $origSel, $assocType );
  4012.             string $select = "select -r ";
  4013.             for ( $sel in $newSel )
  4014.                 $select += "\"" + $sel + "\" ";
  4015.             eval $select;
  4016.         }
  4017.         else
  4018.         {
  4019. //            warning( "Can't figure out the type from the blind data templates." );
  4020. //            warning( "Selection won't be converted and only selected components will be examined." );
  4021.         }
  4022.  
  4023.         if ( !$doColor )
  4024.         {
  4025.             // Then we just do the $cmd and select the result.
  4026.             // If there is nothing returned from the $cmd, we
  4027.             // clear the selection.
  4028.  
  4029.             // You might uncomment out the following print statement
  4030.             // to see (in the script editor) what the arguments are to
  4031.             // the command. This can be useful for debugging as well as
  4032.             // to give you ideas on how to extend the blind data editor.
  4033.             // For this command, the documentation on the polyColorBlindData
  4034.             // command should describe all of the different flags we're using.
  4035.             print( $cmd + "\n" );
  4036.             string $result[] = `eval( $cmd )`;
  4037.             if ( size( $result ) )
  4038.             {
  4039.                 select -cl;
  4040.                 string $cmd = "select -r";
  4041.                 for ( $name in $result )
  4042.                 {
  4043.                     $cmd += " ";
  4044.                     $cmd += $name;
  4045.                 }
  4046.                 eval $cmd;
  4047.             }
  4048.             else        
  4049.             {
  4050.                 select -cl;
  4051.             }
  4052.         }
  4053.         else
  4054.         {
  4055.             // Evaluate the command (which colors the geom for us)
  4056.             // and restore the selection to what it was.
  4057.             
  4058.             // You might uncomment out the following print statement
  4059.             // to see (in the script editor) what the arguments are to
  4060.             // the command. This can be useful for debugging as well as
  4061.             // to give you ideas on how to extend the blind data editor.
  4062.             // For this command, the documentation on the polyColorBlindData
  4063.             // command should describe all of the different flags we're using.
  4064.             print( $cmd + "\n" );
  4065.             eval( $cmd );
  4066.  
  4067.             string $select = "select -r ";
  4068.             for ( $sel in $origSel )
  4069.                 $select += "\"" + $sel + "\" ";
  4070.             eval $select;
  4071.         }
  4072.     }
  4073. }
  4074.  
  4075. global proc bdeQuery()
  4076. {
  4077.     bdeDoQueryColor( 0 );
  4078. }
  4079.  
  4080. global proc bdeColor()
  4081. {
  4082.     bdeDoQueryColor( 1 );
  4083.     refresh;
  4084. }
  4085.  
  4086. // What follows is most of the methods for the type Editor tab.
  4087. // Most of these have 't' or 'T' somewhere in the name to indicate
  4088. // it's for the type Editor (the t was initailly for 'Template' - perhaps
  4089. // a poor choice, but...
  4090.  
  4091. // Check to see if we should enable the ranged box and fields
  4092. // If 'fill' is true, we set these based on the selected template's range 
  4093. // settings
  4094. global proc bdeTRangeCheck( int $i, int $fill )
  4095. {    
  4096.     global int $bdeEditingTemplate;
  4097.     if ( $bdeEditingTemplate )
  4098.         return;
  4099.  
  4100.     string $control;
  4101.     int $ranged;
  4102.     if ( $fill )
  4103.     {        
  4104.         int $id = `intField -q -v bdeTTypeId`;
  4105.         string $bdt = getTemplateNameFromId( $id );
  4106.         if ( $bdt != "" )
  4107.         {
  4108.             $attr = getLongName( $bdt, $i );
  4109.             $ranged = getRanged( $bdt, $attr );
  4110.             $control = "bdeTRanged" + $i;        
  4111.             checkBox -e -en false -v $ranged $control;
  4112.  
  4113.             if ($ranged) {
  4114.                 float $min = getMinVal( $bdt, $attr );
  4115.                 $control = "bdeTIntMin" + $i;
  4116.                 intField -e -en false -v $min $control;
  4117.                 $control = "bdeTFloatMin" + $i;
  4118.                 floatField -e -en false -v $min $control;
  4119.  
  4120.                 float $max = getMaxVal( $bdt, $attr );
  4121.                 $control = "bdeTIntMax" + $i;
  4122.                 intField -e -en false -v $max $control;
  4123.                 $control = "bdeTFloatMax" + $i;
  4124.                 floatField -e -en false -v $max $control;
  4125.             }
  4126.         }
  4127.     }
  4128.  
  4129.     int $freeSet = `checkBox -q -v bdeTFreeSet`;
  4130.     $control = "bdeTDataType" + $i;
  4131.     string $dataType = `optionMenu -q -v $control`;
  4132.     
  4133.     if ( !$freeSet || 
  4134.           $dataType == "string" || $dataType == "boolean" || $dataType == "binary" )
  4135.     {
  4136.         $control = "bdeTRangeFrame" + $i;
  4137.         frameLayout -e -cl true $control;
  4138.         $control = "bdeTIntMinMax" + $i;
  4139.         frameLayout -e -cl true $control;
  4140.         $control = "bdeTFloatMinMax" + $i;
  4141.         frameLayout -e -cl true $control;
  4142.         return;
  4143.     }    
  4144.  
  4145.     $control = "bdeTRangeFrame" + $i;
  4146.     frameLayout -e -cl false $control;    
  4147.  
  4148.     $control = "bdeTRanged" + $i;
  4149.     $ranged = `checkBox -q -v $control`;
  4150.     if ( !$ranged )
  4151.     {
  4152.         $control = "bdeTIntMinMax" + $i;
  4153.         frameLayout -e -cl true $control;
  4154.         $control = "bdeTFloatMinMax" + $i;
  4155.         frameLayout -e -cl true $control;
  4156.         return;
  4157.     }
  4158.     
  4159.     if ( $dataType == "float" || $dataType == "double" )
  4160.     {
  4161.         $control = "bdeTIntMinMax" + $i;
  4162.         frameLayout -e -cl true $control;
  4163.         $control = "bdeTFloatMinMax" + $i;
  4164.         frameLayout -e -cl false $control;
  4165.     }
  4166.     else
  4167.     {
  4168.         $control = "bdeTIntMinMax" + $i;
  4169.         frameLayout -e -cl false $control;
  4170.         $control = "bdeTFloatMinMax" + $i;
  4171.         frameLayout -e -cl true $control;
  4172.     }
  4173. }
  4174.  
  4175. // How many data descriptors exist in the layout
  4176. proc int tNumDescriptors()
  4177. {
  4178.     int $numUsed = 0;
  4179.     string $children[] = `columnLayout -q -ca bdeTDescriptorLayout`;
  4180.     int $nbDesc = size( $children );
  4181.     for ( $i = 0; $i < $nbDesc; $i++ )
  4182.     {
  4183.         $layout = "bdeTDescriptor" + $i;
  4184.         if ( !`frameLayout -q -cl $layout` )
  4185.             $numUsed++;
  4186.         else
  4187.             return $numUsed;
  4188.     }
  4189.  
  4190.     return $numUsed;
  4191. }
  4192.  
  4193. // Do the range check on each of the data descriptors
  4194. global proc bdeTFreeSetChanged()
  4195. {
  4196.     int $numDesc = tNumDescriptors();
  4197.     for ( $i = 0; $i < $numDesc; $i++ )
  4198.     {
  4199.         bdeTRangeCheck( $i, 0 );
  4200.     }
  4201. }
  4202.  
  4203. // Turn on appropriate buttons
  4204. global proc bdeTEnableButtons()
  4205. {
  4206.     global string $bdeTPresetLayout;
  4207.  
  4208.     button -e -vis true bdeNewDescriptorButton;
  4209.     button -e -vis true bdeNewPresetButton;
  4210.  
  4211.     string $children[] = `columnLayout -q -ca $bdeTPresetLayout`;
  4212.     for ( $child in $children )
  4213.     {
  4214.         $layout = $bdeTPresetLayout + "|" + $child;
  4215.         $control = $layout + "|" + "newButton";
  4216.         button -e -vis true $control;
  4217.     }
  4218. }
  4219.  
  4220. // Turn off appropriate buttons
  4221. global proc bdeTDisableButtons()
  4222. {
  4223.     global string $bdeTPresetLayout;
  4224.  
  4225.     button -e -vis false bdeNewDescriptorButton;
  4226.     button -e -vis false bdeNewPresetButton;
  4227.  
  4228.     string $children[] = `columnLayout -q -ca $bdeTPresetLayout`;
  4229.     for ( $child in $children )
  4230.     {
  4231.         $control = $bdeTPresetLayout + "|" + $child + "|presetNameLayout|deleteButton";
  4232.         button -e -vis false $control;
  4233.     }
  4234. }
  4235.  
  4236. // Delete the given preset
  4237. global proc bdeTDeletePreset( string $layout )
  4238. {
  4239.     deleteUI -lay $layout;
  4240. }
  4241.  
  4242. // How many presets exist in the presetLayout
  4243. // (This says nothing about the template or how many are filled)
  4244. proc int tNumPresets()
  4245. {
  4246.     global string $bdeTPresetLayout;
  4247.     string $children[] = `columnLayout -q -ca $bdeTPresetLayout`;
  4248.     return size( $children );
  4249. }
  4250.  
  4251. // Delete all of the presets
  4252. global proc bdeTDestroyPresets()
  4253. {
  4254.     global string $bdeTPresetLayout;
  4255.  
  4256.     string $children[] = `columnLayout -q -ca $bdeTPresetLayout`;
  4257.     string $layout;
  4258.  
  4259.     for ( $child in $children )
  4260.     {
  4261.         $layout = $bdeTPresetLayout + "|" + $child;
  4262.         deleteUI -lay $child;
  4263.     }
  4264. }
  4265.  
  4266. // Empty out the given descriptor
  4267. global proc bdeTClearDescriptor( int $i )
  4268. {
  4269.     string $control = "bdeTLongName" + $i;
  4270.     textField -e -tx "" -en true $control;
  4271.  
  4272.     $control = "bdeTShortName" + $i;
  4273.     textField -e -tx "" -en true $control;
  4274.  
  4275.     $control = "bdeTDataType" + $i;
  4276.     optionMenu -e -v "double" -en true $control;
  4277.  
  4278.     $control = "bdeTRangeFrame" + $i;
  4279.     frameLayout -e -cl true $control;
  4280.  
  4281.     $control = "bdeTRanged" + $i;
  4282.     checkBox -e -v 0 -en true $control;
  4283.  
  4284.     $control = "bdeTIntMinMax" + $i;
  4285.     frameLayout -e -cl true $control;
  4286.  
  4287.     $control = "bdeTIntMin" + $i;
  4288.     intField -e -v 0 -en true $control;
  4289.     $control = "bdeTIntMax" + $i;
  4290.     intField -e -v 100 -en true $control;
  4291.  
  4292.     $control = "bdeTFloatMinMax" + $i;
  4293.     frameLayout -e -cl true $control;
  4294.  
  4295.     $control = "bdeTFloatMin" + $i;
  4296.     floatField -e -v 0 -en true $control;
  4297.     $control = "bdeTFloatMax" + $i;
  4298.     floatField -e -v 1.0 -en true $control;
  4299. }
  4300.  
  4301. global proc bdeTCollapseAndClearDescriptors()
  4302. {
  4303.     string $children[] = `columnLayout -q -ca bdeTDescriptorLayout`;
  4304.     int $numDesc = size( $children );
  4305.     for ( $i = 0; $i < $numDesc; $i++ )
  4306.     {
  4307.         bdeTClearDescriptor( $i );
  4308.         $layout = "bdeTDescriptor" + $i;
  4309.         frameLayout -e -cl true $layout;
  4310.     }
  4311. }
  4312.  
  4313. global proc bdeTOpenDescriptor( int $i )
  4314. {
  4315.     string $layout = "bdeTDescriptor" + $i;
  4316.     if ( !`frameLayout -q -ex $layout` )
  4317.         bdeTBuildDescriptor( $i );
  4318.     frameLayout -e -cl false $layout;
  4319. }
  4320.  
  4321. // Create the given descriptor and all of it's associated
  4322. // controls
  4323. global proc bdeTBuildDescriptor( int $i )
  4324. {    
  4325.     // We just add one to the this layout.
  4326.     // Hence assumption is that any preceeding ones
  4327.     // should be there already.
  4328.     setParent bdeTDescriptorLayout;
  4329.  
  4330.     string $layout = "bdeTDescriptor" + $i;
  4331.     // It's a frameLayout - so we can collapse it
  4332.     // (but because -bv is false the user can't collapse it)
  4333.     frameLayout -cll true -cl true -lv false -bv false $layout;
  4334.  
  4335.         string $command = "bdeTValueChanged " + $i;        
  4336.         columnLayout -adj true -rs 5;
  4337.             rowColumnLayout -nc 2;
  4338.                 text -l "Long name";
  4339.                 string $control = "bdeTLongName" + $i;
  4340.                 textField -cc bdeTTypeNameChange $control;
  4341.  
  4342.                 text -l "Short name";
  4343.                 $control = "bdeTShortName" + $i;
  4344.                 textField $control;
  4345.  
  4346.                 // Default is "double"
  4347.                 text -l "Data type";
  4348.                 $control = "bdeTDataType" + $i;
  4349.                 optionMenu -cc $command $control;
  4350.                     menuItem -l "double";
  4351.                     menuItem -l "int";
  4352.                     menuItem -l "hex";
  4353.                     menuItem -l "boolean";
  4354.                     menuItem -l "string";
  4355.                     menuItem -l "binary";
  4356.             setParent ..;
  4357.  
  4358.             // We create all of the range frames, and they start off collapsed
  4359.             $control = "bdeTRangeFrame" + $i;
  4360.             frameLayout -cll true -cl true -lv false -bv false $control;
  4361.                 rowColumnLayout -nc 2;
  4362.                     separator -st "none";
  4363.                     $control = "bdeTRanged" + $i;
  4364.                     checkBox -l "Ranged" -cc $command $control;
  4365.                 setParent ..;
  4366.             setParent ..;
  4367.  
  4368.             $control = "bdeTIntMinMax" + $i;
  4369.             frameLayout -cll true -cl true -lv false -bv false $control;
  4370.                 rowColumnLayout -nc 2;
  4371.                     text -l "Min";
  4372.                     $control = "bdeTIntMin" + $i;
  4373.                     intField $control;
  4374.                     text -l "Max";
  4375.                     $control = "bdeTIntMax" + $i;
  4376.                     intField $control;
  4377.                 setParent ..;
  4378.             setParent ..;
  4379.  
  4380.             $control = "bdeTFloatMinMax" + $i;
  4381.             frameLayout -cll true -cl true -lv false -bv false $control;
  4382.                 rowColumnLayout -nc 2;
  4383.                     text -l "Min";
  4384.                     $control = "bdeTFloatMin" + $i;
  4385.                     floatField $control;
  4386.                     text -l "Max";
  4387.                     $control = "bdeTFloatMax" + $i;
  4388.                     floatField $control;
  4389.                 setParent ..;
  4390.             setParent ..;
  4391.  
  4392.             separator -w 300 -h 15 -st "in";
  4393.  
  4394.         setParent ..;
  4395.     setParent ..;
  4396. }
  4397.  
  4398. // Allow user-editing of all the presets, and 
  4399. // enable the newPreset button.
  4400. proc tEnablePresets()
  4401. {
  4402.     global string $bdeTPresetLayout;
  4403.     global int $bdeEditingTemplate;
  4404.  
  4405.     string $layout, $control;
  4406.     string $children[] = `columnLayout -q -ca $bdeTPresetLayout`;
  4407.     int $numDesc = tNumDescriptors();
  4408.     int $numPresets = tNumPresets();
  4409.  
  4410.     for ( $i = 0; $i < $numPresets; $i++ )
  4411.     {
  4412.         $control = $bdeTPresetLayout + "|" + $children[$i];
  4413.         $control += "|presetNameLayout|presetTagName";
  4414.         textField -e -en true $control;
  4415.         for ( $j = 0; $j < $numDesc; $j++ )
  4416.         {
  4417.             $layout = $bdeTPresetLayout + "|" + $children[$i] + "|presetValueLayout" + $j;
  4418.             $control = $layout + "|presetValue" + $j;
  4419.             textField -e -en true $control;
  4420.         }
  4421.     }
  4422.  
  4423.     button -e -vis true bdeNewPresetButton;
  4424. }
  4425.  
  4426. // (Re)Build all of the existing presets
  4427. // filling in the appropriate attr names
  4428. global proc bdeTRebuildPresets()
  4429. {
  4430.     global string $bdeTPresetLayout;
  4431.  
  4432.     string $layout, $control;
  4433.     string $children[] = `columnLayout -q -ca $bdeTPresetLayout`;
  4434.     int $numDesc = tNumDescriptors();
  4435.     int $numPresets = tNumPresets();
  4436.  
  4437.     for ( $i = 0; $i < $numPresets; $i++ )
  4438.     {        
  4439.         for ( $j = 0; $j < $numDesc; $j++ )
  4440.         {
  4441.             $layout = $bdeTPresetLayout + "|" + $children[$i] + "|presetValueLayout" + $j;
  4442.             $control = "bdeTLongName" + $j;
  4443.             $value = `textField -q -tx $control`;
  4444.             if ( `rowLayout -q -ex $layout` )
  4445.             {
  4446.                 $control = $layout + "|presetDataName" + $j;
  4447.                 text -e -l $value $control;
  4448.             }
  4449.             else
  4450.             {
  4451.                 $layout = $bdeTPresetLayout + "|" + $children[$i];
  4452.                 setParent $layout;
  4453.                 $layout = "presetValueLayout" + $j;
  4454.                 rowLayout -nc 2 -cal 1 "right" $layout;
  4455.                     $control = "presetDataName" + $j;
  4456.                     text -l $value $control;
  4457.                     $control = "presetValue" + $j;
  4458.                     textField -w 100 $control;
  4459.                 setParent ..;
  4460.                 rowLayout -e -cal 1 "right" $layout;
  4461.             }
  4462.         }
  4463.         $layout = $bdeTPresetLayout + "|" + $children[$i] + "|presetValueLayout" + $numDesc;
  4464.         if ( `rowLayout -q -ex $layout` )
  4465.             deleteUI -lay $layout;
  4466.     }
  4467. }
  4468.  
  4469. // Open a new descriptor. If one exists and is collapsed,
  4470. // it's cleared and opened. Otherwise, a new one is created.
  4471. global proc bdeNewDescriptor()
  4472. {
  4473.     string $children[] = `columnLayout -q -ca bdeTDescriptorLayout`;
  4474.     int $numDesc = size( $children );
  4475.     for ( $i = 0; $i < $numDesc; $i++ )
  4476.     {
  4477.         $layout = "bdeTDescriptor" + $i;
  4478.         if ( `frameLayout -q -cl $layout` )
  4479.         {
  4480.             bdeTClearDescriptor( $i );
  4481.             frameLayout -e -cl false $layout;
  4482.             bdeTFreeSetChanged();
  4483.             bdeTRebuildPresets();
  4484.             return;
  4485.         }
  4486.     }
  4487.  
  4488.     bdeTBuildDescriptor( $numDesc );
  4489.     $layout = "bdeTDescriptor" + $numDesc;
  4490.     frameLayout -e -cl false $layout;
  4491.     bdeTFreeSetChanged();
  4492.     bdeTRebuildPresets();
  4493. }
  4494.  
  4495. // I had a remove button, in case you created too many and
  4496. // decided you didn't want some of them, but i decided to axe this
  4497. // for simplicity sake. If you hit the 'New' button too many times, 
  4498. // you've gotta start over with a new template. That's not so bad, is it?
  4499. global proc bdeRemoveDescriptor()
  4500. {
  4501.     string $children[] = `columnLayout -q -ca bdeTDescriptorLayout`;
  4502.     int $numDesc = size( $children );
  4503.     for ( $i = 0; $i < $numDesc; $i++ )
  4504.     {
  4505.         $layout = "bdeTDescriptor" + $i;
  4506.         if ( `frameLayout -q -cl $layout` )
  4507.         {
  4508.             if ( $i > 1 )
  4509.             {
  4510.                 $layout = "bdeTDescriptor" + ($i-1);
  4511.                 frameLayout -e -cl true $layout;
  4512.                 bdeTClearDescriptor( $i-1 );
  4513.                 return;
  4514.             }
  4515.             else
  4516.                 return;
  4517.         }
  4518.     }
  4519.  
  4520.     if ( $numDesc > 1 )
  4521.     {
  4522.         $layout = "bdeTDescriptor" + ($numDesc-1);
  4523.         frameLayout -e -cl true $layout;
  4524.         bdeTClearDescriptor( $numDesc-1 );        
  4525.     }
  4526.  
  4527.     bdeTRebuildPresets();
  4528. }
  4529.  
  4530. // Fill the given descriptor with the appropriate data
  4531. // from the selected blind data template.
  4532. global proc bdeTFillDescriptor( int $i )
  4533. {
  4534.     int $id = `intField -q -v bdeTTypeId`;
  4535.     if ( idDefined( $id ) )
  4536.     {
  4537.         string $bdt = getTemplateNameFromId( $id );
  4538.         if ( $bdt == "" )
  4539.             return;
  4540.  
  4541.         int $dataCount = getDataCount( $bdt );
  4542.         if ( $i >= $dataCount )
  4543.             return;
  4544.  
  4545.         string $name = getLongName( $bdt, $i );
  4546.         string $control = "bdeTLongName" + $i;
  4547.         textField -e -en false -tx $name $control;
  4548.  
  4549.         $name = getShortName( $bdt, $i );
  4550.         $control = "bdeTShortName" + $i;
  4551.         textField -e -en false -tx $name $control;
  4552.  
  4553.         string $dataType = getDataType( $bdt, $i );
  4554.         $control = "bdeTDataType" + $i;
  4555.         optionMenu -e -en false -v $dataType $control;
  4556.  
  4557.         // This call figures out what to do with the
  4558.         // free set and ranged stuff for this descriptor
  4559.         bdeTRangeCheck( $i, true );
  4560.     }
  4561. }
  4562.  
  4563. // Create a new preset, either because user hit the new preset
  4564. // button or if an id was selected that has presets defined
  4565. // First field is the name of the preset, then there is one field
  4566. // for each of the data descriptors.
  4567. global proc bdeTNewPreset()
  4568. {
  4569.     global string $bdeTPresetLayout;
  4570.  
  4571.     setParent $bdeTPresetLayout;
  4572.  
  4573.     $layout = `columnLayout -adj true`;
  4574.     // Couldn't quite get the alignment right on this...
  4575. //        rowLayout -nc 3 -cal 1 "left" -cal 2 "center" -cal 3 "right" presetNameLayout;
  4576. //        rowLayout -nc 4 -cal 4 "center" presetNameLayout;
  4577.         rowLayout -nc 3 -cal 3 "center" presetNameLayout;
  4578.             text -l "Preset name";
  4579.             textField -w 90 presetTagName;
  4580. //            separator -st "none";
  4581.             button -l "Delete" -w 65 -c ( "bdeTDeletePreset \"" + $layout + "\"" ) deleteButton;
  4582.         setParent ..;
  4583.  
  4584.         int $numDesc = tNumDescriptors();
  4585.         for ( $i = 0; $i < $numDesc; $i++ )
  4586.         {
  4587.             $layout = "presetValueLayout" + $i;
  4588.             rowLayout -nc 2 -cal 1 "right" $layout;
  4589.                 $control = "bdeTLongName" + $i;
  4590.                 $attr = `textField -q -tx $control`;
  4591.                 $control = "presetDataName" + $i;
  4592.                 text -l $attr $control;
  4593.  
  4594.                 $control = "presetValue" + $i;
  4595.                 textField -w 90 $control;                                
  4596.  
  4597. //                separator -st "none";
  4598.             setParent ..;
  4599.             rowLayout -e -cal 1 "right" $layout;
  4600.         }
  4601.  
  4602.         separator -w 300 -h 8 -st "in";
  4603.  
  4604.     setParent ..;
  4605. }
  4606.  
  4607. // Fill the presets with the ones that are set from the 
  4608. // selected blind data template.
  4609. global proc bdeTFillPresets()
  4610. {
  4611.     global string $bdeTPresetLayout;
  4612.     string $control;
  4613.     string $value;
  4614.     string $layout;
  4615.     int $tagCount;
  4616.     
  4617.     int $id = `intField -q -v bdeTTypeId`;
  4618.     if ( !idDefined( $id ) )
  4619.         return;
  4620.     string $bdt = getTemplateNameFromId( $id );
  4621.     if ( $bdt == "" )
  4622.         return;
  4623.  
  4624.     int $numPresets = getPresetCount( $bdt );
  4625.     int $dataCount = getDataCount( $bdt );
  4626.  
  4627.     if ( 0 == $dataCount || 0 == $numPresets )
  4628.         return;
  4629.  
  4630.     string $children[] = `columnLayout -q -ca $bdeTPresetLayout`;
  4631.     for ( $i = 0; $i < $numPresets; $i++ )
  4632.     {
  4633.         $value = getPresetName( $bdt, $i );
  4634.         $control = $bdeTPresetLayout + "|" + $children[$i] + "|presetNameLayout|presetTagName";                
  4635.         textField -e -en false -tx $value $control;
  4636.  
  4637.         for ( $j = 0; $j < $dataCount; $j++ )
  4638.         {
  4639.             $attr = getLongName( $bdt, $j );
  4640.             $layout = $bdeTPresetLayout + "|" + $children[$i] + "|presetValueLayout" + $j;
  4641.             $value = getPresetVal( $bdt, $i, $attr );
  4642.             $control = $layout + "|presetValue" + $j;
  4643.             if ( `textField -q -ex $control` )
  4644.                 textField -e -en false -tx $value $control;
  4645.         }
  4646.     }
  4647. }
  4648.  
  4649. // This clears everything out and enables the buttons, etc.
  4650. // Happens on the 'New' template button or when you want
  4651. // similar behaviour
  4652. global proc bdeNewTemplate( int $clearType )
  4653. {
  4654.     global int $bdeEditingTemplate = 0;
  4655.  
  4656.     // We may be getting called from the initCallback on the first
  4657.     // open of the panel. If that's the case, this intField doesn't
  4658.     // exist, and we should return gracefully.
  4659.     if ( !`intField -q -ex bdeTTypeId` )
  4660.         return;
  4661.  
  4662.     if ( $clearType )
  4663.         intField -e -v 0 -en true bdeTTypeId;
  4664.  
  4665.     textField -e -tx "" -en true bdeTTypeName;
  4666.     optionMenu -e -v "any" -en true bdeTAssocType;
  4667.     checkBox -e -en true bdeTFreeSet;
  4668.  
  4669.     string $children[] = `columnLayout -q -ca bdeTDescriptorLayout`;
  4670.     int $numDesc = size( $children );
  4671.     for ( $i = 0; $i < $numDesc; $i++ )
  4672.     {
  4673.         $layout = "bdeTDescriptor" + $i;
  4674.         if ( 0 == $i )
  4675.             frameLayout -e -cl false $layout;
  4676.         else
  4677.             frameLayout -e -cl true $layout;
  4678.  
  4679.         bdeTClearDescriptor( $i );
  4680.     }
  4681.  
  4682.     textScrollList -e -da bdeTemplateList;
  4683.     bdeTFreeSetChanged();
  4684.     bdeTDestroyPresets();
  4685.     bdeTEnableButtons();
  4686. }
  4687.  
  4688. // The id field has changed.
  4689. global proc bdeTIdChange()
  4690. {
  4691.     int $id = `intField -q -v bdeTTypeId`;
  4692.  
  4693.     // Is this an existing template?
  4694.     // If so, fill in the values, disable
  4695.     // buttons so user can't delete data that we can't delete
  4696.     // if it exists in the scene, etc.
  4697.     if ( idDefined( $id ) )
  4698.     {
  4699.         string $bdt = getTemplateNameFromId( $id );
  4700.         intField -e -en false bdeTTypeId;
  4701.         string $name = getTag( $bdt );
  4702.         textField -e -en false -tx $name bdeTTypeName;
  4703.         string $assocType = getAssocType( $bdt );
  4704.         if ( $assocType != "" )
  4705.             optionMenu -e -en false -v $assocType bdeTAssocType;
  4706.         else
  4707.             optionMenu -e -en false -v "any" bdeTAssocType;
  4708.         int $freeSet = getFreeSet( $bdt );
  4709.         checkBox -e -en false -v $freeSet bdeTFreeSet;
  4710.         
  4711.         bdeTCollapseAndClearDescriptors();
  4712.         bdeTDestroyPresets();
  4713.  
  4714.         int $dataCount = getDataCount( $bdt );
  4715.         for ( $i = 0; $i < $dataCount; $i++ )
  4716.         {
  4717.             string $layout = "bdeTDescriptor" + $i;
  4718.             if ( !`frameLayout -q -ex $layout` )
  4719.                 bdeTBuildDescriptor( $i );
  4720.  
  4721.             bdeTFillDescriptor( $i );
  4722.  
  4723.             frameLayout -e -cl false $layout;
  4724.         }
  4725.  
  4726.         int $presetCount = getPresetCount( $bdt );
  4727.         for ( $i = 0; $i < $presetCount; $i++ )
  4728.             bdeTNewPreset();
  4729.  
  4730.         bdeTRebuildPresets();
  4731.         bdeTFillPresets();
  4732.         bdeTDisableButtons();
  4733.     }
  4734.     // If the id's not defined, this should be a 'new' template already.
  4735.     // Calling bdeNewTemplate will clear out all values if they've been
  4736.     // entered (and would be very annoying if they changed their mind about
  4737.     // the id after entering everything)
  4738. //    else
  4739. //    {
  4740. //        bdeNewTemplate( false );
  4741. //    }
  4742. }
  4743.  
  4744. // If one of the type names changed, we'll rebuild all the presets, as they
  4745. // have the type names in them (before each preset value field)
  4746. global proc bdeTTypeNameChange()
  4747. {
  4748.     bdeTRebuildPresets();
  4749. }
  4750.  
  4751. // They selected a pre-existing template. If they were editing one, they're not
  4752. // anymore!
  4753. global proc bdeTNameListChange()
  4754. {
  4755.     int $id = getTemplateTagId();
  4756.  
  4757.     if ( $id == -1 )
  4758.         return;
  4759.  
  4760.     global int $bdeEditingTemplate = 0;
  4761.  
  4762.     intField -e -v $id bdeTTypeId;
  4763.     bdeTIdChange();
  4764. }
  4765.  
  4766. // Just do a range check and rebuild the presets if one of the
  4767. // values changed.
  4768. global proc bdeTValueChanged( int $i )
  4769. {
  4770.     bdeTRangeCheck( $i, 0 );
  4771.  
  4772.     bdeTRebuildPresets();
  4773. }
  4774.  
  4775. // This is called before saving the templates to make sure all 
  4776. // of the entered data is legit.
  4777. // This function could (should?) be expanded upon - to make
  4778. // sure that the preset vals match the data type, etc.
  4779. proc int tCheckValues()
  4780. {
  4781.     global int $bdeEditingTemplate;
  4782.     global string $bdeTPresetLayout;
  4783.  
  4784.     int $id = `intField -q -v bdeTTypeId`;
  4785.     if ( $id < 0 )
  4786.     {
  4787.         warning( "typeId must be positive." );
  4788.         return 0;
  4789.     }
  4790.  
  4791.     if ( !$bdeEditingTemplate )
  4792.     {
  4793.         if ( idDefined( $id ) )
  4794.         {
  4795.             warning( "That id # is already defined. Please choose another." );
  4796.             return 0;
  4797.         }
  4798.     }
  4799.     string $typeTag = `textField -q -tx bdeTTypeName`;
  4800.     if ( $typeTag == "" )
  4801.     {
  4802.         warning( "Must specify a name for this blind data Id." );
  4803.         return 0;
  4804.     }
  4805.  
  4806.     if ( !$bdeEditingTemplate )
  4807.     {
  4808.         if ( tagDefined( $typeTag ) )
  4809.         {
  4810.             warning( "That typeTag is already defined. Please choose another." );
  4811.             return 0;
  4812.         }
  4813.     }
  4814.  
  4815.     int $numDesc = tNumDescriptors();
  4816.     int $numPresets = tNumPresets();
  4817.  
  4818.     string $longName[];
  4819.     string $shortName[];
  4820.  
  4821.     // Make sure they've filled long and short names
  4822.     for ( $i = 0; $i < $numDesc; $i++ )
  4823.     {
  4824.         $control = "bdeTLongName" + $i;
  4825.         $longName[$i] = `textField -q -tx $control`;
  4826.         $control = "bdeTShortName" + $i;
  4827.         $shortName[$i] = `textField -q -tx $control`;
  4828.  
  4829.         if ( $longName[$i] == "" || $shortName[$i] == "" )
  4830.         {
  4831.             warning( "Must specify longName and shortName for each data descriptor." );
  4832.             return 0;
  4833.         }
  4834.     }
  4835.  
  4836.     string $children[] = `columnLayout -q -ca $bdeTPresetLayout`;    
  4837.     for ( $i = 0; $i < $numPresets; $i++ )
  4838.     {
  4839.         string $presetName;
  4840.         string $presetVal[];
  4841.  
  4842.         $control = $bdeTPresetLayout + "|" + $children[$i] + "|presetNameLayout|presetTagName";                
  4843.         $presetName = `textField -q -tx $control`;
  4844.         if ( $presetName == "" )
  4845.         {
  4846.             warning( "Must specify a name for each preset." );
  4847.             return 0;
  4848.         }
  4849.  
  4850.         for ( $j = 0; $j < $numDesc; $j++ )
  4851.         {
  4852.             $layout = $bdeTPresetLayout + "|" + $children[$i] + "|presetValueLayout" + $j;
  4853.             $control = $layout + "|presetValue" + $j;
  4854.             $presetVal[$j] = `textField -q -tx $control`;
  4855.             if ( $presetVal[$j] == "" )
  4856.             {
  4857.                 warning( "Must fill all preset values." );
  4858.                 return 0;
  4859.             }
  4860.             // Could check here if $presetVal[$j] matches the $dataType[$j]...
  4861.         }
  4862.     }        
  4863.  
  4864.     return 1;
  4865. }
  4866.  
  4867. // If user was 'Edit'ing a pre-existing template, we don't do as much as if 
  4868. // they are saving a new one...
  4869. // For editing, only the typeTag, assocType,
  4870. // and presets are editable.
  4871. global proc bdeSaveEditedTemplate()
  4872. {
  4873.     global int $bdeEditingTemplate;
  4874.     global string $bdeTPresetLayout;
  4875.  
  4876.     int $id = `intField -q -v bdeTTypeId`;
  4877.     string $bdt = getTemplateNameFromId( $id );
  4878.     if ( $bdt == "" )
  4879.         return;
  4880.     $bdeEditingTemplate = 0;
  4881.     string $typeTag = `textField -q -tx bdeTTypeName`;
  4882.  
  4883.     int $numDesc = tNumDescriptors();
  4884.     int $numPresets = tNumPresets();
  4885.  
  4886.     string $assocType = `optionMenu -q -v bdeTAssocType`;
  4887.     setAssocType( $bdt, $assocType );
  4888.     int $freeSet = `checkBox -q -v bdeTFreeSet`;
  4889.     setFreeSet( $bdt, $freeSet );
  4890.     string $longName[];
  4891.  
  4892.     for ( $i = 0; $i < $numDesc; $i++ )
  4893.     {
  4894.         $control = "bdeTLongName" + $i;
  4895.         $longName[$i] = `textField -q -tx $control`;
  4896.     }
  4897.  
  4898.     string $children[] = `columnLayout -q -ca $bdeTPresetLayout`;    
  4899.     string $presetName;
  4900.     string $presetVal[];
  4901.     for ( $i = 0; $i < $numPresets; $i++ )
  4902.     {        
  4903.         $control = $bdeTPresetLayout + "|" + $children[$i] + "|presetNameLayout|presetTagName";                
  4904.         $presetName = `textField -q -tx $control`;        
  4905.         for ( $j = 0; $j < $numDesc; $j++ )
  4906.         {
  4907.             $layout = $bdeTPresetLayout + "|" + $children[$i] + "|presetValueLayout" + $j;
  4908.             $control = $layout + "|presetValue" + $j;
  4909.             $presetVal[$j] = `textField -q -tx $control`;            
  4910.         }
  4911.         setPreset( $bdt, $presetName, $longName, $presetVal, $i );
  4912.     }
  4913.  
  4914.     bdeForceRebuild();    
  4915.     bdeNewTemplate( true );
  4916. }
  4917.  
  4918. // This gets called when the user hits save
  4919. // If they were editing a pre-existing one, we call 
  4920. // bdeSaveEditedTemplate, otherwise, save everything
  4921. global proc bdeSaveTemplate()
  4922. {    
  4923.     global string $bdeTPresetLayout;
  4924.     global int $bdeEditingTemplate;
  4925.     string $control;
  4926.  
  4927.     // Make sure everything's filled in.
  4928.     if ( !tCheckValues() )
  4929.         return;            
  4930.  
  4931.     if ( $bdeEditingTemplate )
  4932.     {
  4933.         bdeSaveEditedTemplate();
  4934.         return;
  4935.     }
  4936.  
  4937.     // Just in case
  4938.     $bdeEditingTemplate = 0;
  4939.  
  4940.     int $id = `intField -q -v bdeTTypeId`;
  4941.     string $typeTag = `textField -q -tx bdeTTypeName`;
  4942.  
  4943.     int $numDesc = tNumDescriptors();
  4944.     int $numPresets = tNumPresets();
  4945.  
  4946.     string $assocType = `optionMenu -q -v bdeTAssocType`;
  4947.     int $freeSet = `checkBox -q -v bdeTFreeSet`;
  4948.  
  4949.     string $longName[];
  4950.     string $shortName[];
  4951.     string $dataType[];
  4952.     int $ranged[];
  4953.     float $min[];
  4954.     float $max[];
  4955.  
  4956.     for ( $i = 0; $i < $numDesc; $i++ )
  4957.     {
  4958.         $control = "bdeTLongName" + $i;
  4959.         $longName[$i] = `textField -q -tx $control`;
  4960.  
  4961.         $control = "bdeTShortName" + $i;
  4962.         $shortName[$i] = `textField -q -tx $control`;
  4963.  
  4964.         $control = "bdeTDataType" + $i;
  4965.         $dataType[$i] = `optionMenu -q -v $control`;        
  4966.             
  4967.         $control = "bdeTRanged" + $i;
  4968.         $ranged[$i] = `checkBox -q -v $control`;
  4969.  
  4970.         if ( $dataType[$i] == "int" )
  4971.         {
  4972.             $control = "bdeTIntMin" + $i;
  4973.             $min[$i] = `intField -q -v $control`;
  4974.     
  4975.             $control = "bdeTIntMax" + $i;
  4976.             $max[$i] = `intField -q -v $control`;
  4977.         }
  4978.         else
  4979.         {
  4980.             $control = "bdeTFloatMin" + $i;
  4981.             $min[$i] = `floatField -q -v $control`;
  4982.     
  4983.             $control = "bdeTFloatMax" + $i;
  4984.             $max[$i] = `floatField -q -v $control`;
  4985.         }
  4986.     }
  4987.  
  4988.     string $cmd = "blindDataType -id " + $id;
  4989.     string $dt;
  4990.     for ( $i = 0; $i < $numDesc; $i++ )
  4991.     {
  4992.         if ( $dataType[$i] == "hex" )
  4993.             $dt = "int";
  4994.         else
  4995.             $dt = $dataType[$i];
  4996.         $cmd += " -dt \"" + $dt + "\"";
  4997.         $cmd += " -ldn \"" + $longName[$i] + "\"";
  4998.         $cmd += " -sdn \"" + $shortName[$i] + "\"";
  4999.     }
  5000.  
  5001.     // Create the blindDataType.
  5002.     // Right now we have all the info that blindDataType command cares
  5003.     // about...
  5004. //    print( $cmd + "\n" );
  5005.     string $bdt = `eval( $cmd )`;
  5006.  
  5007.     // Here we check each descriptor for whether it's ranged.
  5008.     // If it's ranged we:
  5009.     // delete the attribute from the newly created blindDataTemplate node
  5010.     // create the attribute again on the same blindDataTemplate node, this
  5011.     //  time with the min and max values added.
  5012.     // This is a dangerous thing to do, but was the only way to specify at
  5013.     // the dg level what the min and max values are - there's no way to 
  5014.     // assign min and max to existing attributes (there is a bug entered for
  5015.     // this somewhere...) Since we know the data type, the long and short names,
  5016.     // and the min and max, it's safe, but be very cautious if you start messing
  5017.     // around with this code!!
  5018.     for ( $i = 0; $i < $numDesc; $i++ )
  5019.     {
  5020.         if ( !$freeSet || !$ranged[$i] )
  5021.             continue;
  5022.  
  5023.         if ( $min[$i] == $max[$i] )
  5024.             continue;
  5025.  
  5026.         string $delCmd = "deleteAttr " + $bdt + "." + $longName[$i];        
  5027.  
  5028.         $cmd = "addAttr -ln " + $longName[$i] + " -sn " + $shortName[$i];
  5029.         switch( $dataType[$i] )
  5030.         {
  5031.         case "string":
  5032.         case "binary":
  5033.         case "boolean":
  5034.             continue; // Don't support ranges for these types!
  5035.         case "int":
  5036.         case "hex":
  5037.             $cmd += " -at long";
  5038.             break;
  5039.         case "float":
  5040.         case "double":
  5041.             $cmd += " -at double";
  5042.             break;
  5043.         }
  5044.  
  5045. //        print( $delCmd + "\n" );
  5046.         eval( $delCmd );
  5047.  
  5048.         $cmd += " -min " + $min[$i];
  5049.         $cmd += " -max " + $max[$i];
  5050.         $cmd += " " + $bdt;
  5051. //        print( $cmd + "\n" );
  5052.         eval( $cmd );
  5053.     }    
  5054.     
  5055.     // All of these set*($bdt,...) calls are using the
  5056.     // user-defined attributes of the new template node. 
  5057.     // They are defined above somewhere (do a search).
  5058.     setTag( $bdt, $typeTag );
  5059.     setAssocType( $bdt, $assocType );
  5060.     setFreeSet( $bdt, $freeSet );
  5061.  
  5062.     setDataCount( $bdt, $numDesc );
  5063.  
  5064.     for ( $i = 0; $i < $numDesc; $i++ )
  5065.     {
  5066.         setLongName( $bdt, $i, $longName[$i] );
  5067.         setDataType( $bdt, $i, $dataType[$i] );
  5068.     }    
  5069.  
  5070.     // The presets are set in the blind data template's 
  5071.     // preset name/value attributes...
  5072.     string $children[] = `columnLayout -q -ca $bdeTPresetLayout`;    
  5073.     for ( $i = 0; $i < $numPresets; $i++ )
  5074.     {
  5075.         string $presetName;
  5076.         string $presetVal[];
  5077.  
  5078.         $control = $bdeTPresetLayout + "|" + $children[$i] + "|presetNameLayout|presetTagName";                
  5079.         $presetName = `textField -q -tx $control`;
  5080.  
  5081.         for ( $j = 0; $j < $numDesc; $j++ )
  5082.         {
  5083.             $layout = $bdeTPresetLayout + "|" + $children[$i] + "|presetValueLayout" + $j;
  5084.             $control = $layout + "|presetValue" + $j;
  5085.             $presetVal[$j] = `textField -q -tx $control`;            
  5086.         }
  5087.         setPreset( $bdt, $presetName, $longName, $presetVal, $i );
  5088.     }
  5089.  
  5090.     bdeForceRebuild();    
  5091.     bdeNewTemplate( true );
  5092. }
  5093.  
  5094. // If the user wants to edit an existing template, we enable the
  5095. // fields that are editable (enabling the rest could jeopardize the
  5096. // existing blind data already assigned in the scene - rather than
  5097. // trying to deal with this rather hairy problem, disallow it. Enabling
  5098. // editing of, say, data types, can lead to lots of problems - do so at
  5099. // your own risk).
  5100. // We also set the $bdeEditingTemplate var to be true so we know 
  5101. // we're in Edit (and not New) mode
  5102. global proc bdeEditTemplate()
  5103. {
  5104.     global int $bdeEditingTemplate;
  5105.  
  5106.     int $id = `intField -q -v bdeTTypeId`;
  5107.     if ( !idDefined( $id ) )
  5108.         return;
  5109.     
  5110.     string $bdt = getTemplateNameFromId( $id );
  5111.     if ( $bdt == "" )
  5112.         return;
  5113.  
  5114.     $bdeEditingTemplate = 1;
  5115.  
  5116.     textField -e -en true bdeTTypeName;
  5117.     optionMenu -e -en true bdeTAssocType;
  5118.     checkBox -e -en true bdeTFreeSet;
  5119.  
  5120.     tEnablePresets();
  5121. }
  5122.  
  5123. // Export the current blind data templates to a file.
  5124. // In most cases the same blind data is going to be used in
  5125. // all scenes for any one game. Best to set it up initially
  5126. // and import or reference it into the scenes.
  5127. // (Referencing will be more convenient if it's possible the
  5128. //  blind data is ever going to change in the game, which is
  5129. //  probably pretty likely...)
  5130. //
  5131. // We select the blindDataTemplates, prompt the user to export
  5132. // them, and then restore the original selection
  5133. global proc bdeExportTemplates()
  5134. {
  5135.     string $sel[] = `ls -sl`;
  5136.  
  5137.     // Bug 150384 check exact type so we don't get subd blind data
  5138.     string $templates[] = `ls -exactType blindDataTemplate`;
  5139.     string $cmd = "select -r ";
  5140.     for ( $bdt in $templates )
  5141.     {
  5142.         $cmd += $bdt;
  5143.         $cmd += " ";
  5144.     }
  5145.     eval $cmd;
  5146.  
  5147.     projectViewer "ExportActive";
  5148.  
  5149.     $cmd = "select -r ";
  5150.     for ( $sl in $sel )
  5151.     {
  5152.         $cmd += $sl;
  5153.         $cmd += " ";
  5154.     }
  5155.     eval $cmd;
  5156. }
  5157.  
  5158. // This func dumps all of the data we care about contained in the blind
  5159. // data template nodes in this scene into the given file.
  5160. // It's actually a callback from the 'fileBrowser' call in bdeDumpTemplates.
  5161. //
  5162. // Does a check to see if the file exists and gives a confirm box to overwrite.
  5163. // Then just writes out all of the data to that file.
  5164. // This can be useful just for a quick visual check of the data, for sharing
  5165. // the data between the level designer and the engine programmer, or for the
  5166. // engine developer to actually parse to ensure that the data in the engine
  5167. // matches the data used in Maya.
  5168. //
  5169. // Easy enough to modify this if it's not printing the data in a format
  5170. // suitable to your parsing, or if you need more info
  5171. // (for instance, the number of blind data templates being printed at the
  5172. // start of the file might make parsing a bit easier).
  5173. global proc int bdeTextExport( string $fileName, string $fileType )
  5174. {
  5175.     string    $line, 
  5176.             $confirm, 
  5177.             $attrName,
  5178.             $presetName,
  5179.             $presetVal;
  5180.  
  5181.     int        $i, $j,
  5182.             $fp, 
  5183.             $ranged, 
  5184.             $dataCount, 
  5185.             $presetCount;
  5186.  
  5187.     if ( "" == $fileName )
  5188.         return 0;
  5189.  
  5190.     if ( `filetest -x $fileName` )
  5191.     {
  5192.         $confirm = `confirmDialog -title "Confirm" -message "File exists. Overwrite?"
  5193.              -button "Yes" -button "No" -defaultButton "Yes"
  5194.              -cancelButton "No" -dismissString "No"`;
  5195.         if ( "No" == $confirm )
  5196.             return 0;
  5197.     }
  5198.  
  5199.     $fp = fopen( $fileName, "w" );
  5200.     if ( 0 == $fp )
  5201.     {
  5202.         warning( "Could not open file " + $fileName );
  5203.         return -1;
  5204.     }
  5205.  
  5206.     // Bug 150384 check exact type so we don't get subd blind data
  5207.     string $nodes[] = `ls -exactType "blindDataTemplate"`;
  5208.     for ( $bdt in $nodes )
  5209.     {
  5210.         $line = "++++++++++++++++++++++++++++++++++++++++++++++\n";
  5211.         fprint( $fp, $line );
  5212.  
  5213.         $line = $bdt + "\n";
  5214.         fprint( $fp, $line );
  5215.  
  5216.         $line = "ID: ";
  5217.         $line += getId( $bdt );
  5218.         $line += "\n";
  5219.         fprint( $fp, $line );
  5220.  
  5221.         $line = "NAME: ";
  5222.         $line += getTag( $bdt );
  5223.         $line += "\n";
  5224.         fprint( $fp, $line );        
  5225.  
  5226.         $line = "ASSOC TYPE: ";
  5227.         $line += getAssocType( $bdt );
  5228.         $line += "\n";
  5229.         fprint( $fp, $line );
  5230.  
  5231.         $line = "FREE SET: ";
  5232.         $line += getFreeSet( $bdt );
  5233.         $line += "\n";
  5234.         fprint( $fp, $line );
  5235.  
  5236.         $dataCount = getDataCount( $bdt );
  5237.         $line = "DATA COUNT: ";
  5238.         $line += $dataCount;
  5239.         $line += "\n";
  5240.         fprint( $fp, $line );        
  5241.  
  5242.         for ( $i = 0; $i < $dataCount; $i++ )
  5243.         {
  5244.             $attrName = getLongName( $bdt, $i );
  5245.             $line = "\tLONG NAME: ";
  5246.             $line += $attrName;
  5247.             $line += "\n";
  5248.             fprint( $fp, $line );
  5249.  
  5250.             $line = "\tSHORT NAME: ";
  5251.             $line += getShortName( $bdt, $i );
  5252.             $line += "\n";
  5253.             fprint( $fp, $line );
  5254.  
  5255.             $line = "\tDATA TYPE: ";
  5256.             $line += getDataType( $bdt, $i );
  5257.             $line += "\n";
  5258.             fprint( $fp, $line );
  5259.  
  5260.             $ranged = getRanged( $bdt, $attrName );
  5261.             $line = "\tRANGED: ";
  5262.             $line += $ranged;
  5263.             $line += "\n";
  5264.             fprint( $fp, $line );
  5265.  
  5266.             if ( $ranged )
  5267.             {
  5268.                 $line = "\t\tMIN VAL: ";
  5269.                 $line += getMinVal( $bdt, $attrName );
  5270.                 $line += "\n";
  5271.                 fprint( $fp, $line );
  5272.  
  5273.                 $line = "\t\tMAX VAL: ";
  5274.                 $line += getMaxVal( $bdt, $attrName );
  5275.                 $line += "\n";
  5276.                 fprint( $fp, $line );
  5277.             }
  5278.  
  5279.             if ( $i != $dataCount-1 )
  5280.             {
  5281.                 $line = "\t---------------\n";
  5282.                 fprint( $fp, $line );
  5283.             }
  5284.             else
  5285.             {
  5286.                 fprint( $fp, "\n" );
  5287.             }
  5288.         }
  5289.  
  5290.         $presetCount = getPresetCount( $bdt );
  5291.         $line = "PRESET COUNT: ";
  5292.         $line += $presetCount;
  5293.         $line += "\n";
  5294.         fprint( $fp, $line );
  5295.  
  5296.         for ( $i = 0; $i < $presetCount; $i++ )
  5297.         {
  5298.             $presetName = getPresetName( $bdt, $i );
  5299.             $line = "\tPRESET NAME: ";
  5300.             $line += $presetName;
  5301.             $line += "\n";
  5302.             fprint( $fp, $line );
  5303.  
  5304.             for ( $j = 0; $j < $dataCount; $j++ )
  5305.             {
  5306.                 $line = "\t\t";
  5307.                 $attrName = getLongName( $bdt, $j );
  5308.                 $line += $attrName;
  5309.                 $line += ": ";
  5310.                 $presetVal = getPresetVal( $bdt, $i, $attrName );
  5311.                 $line += $presetVal;
  5312.                 $line += "\n";
  5313.                 fprint( $fp, $line );
  5314.             }
  5315.         }
  5316.  
  5317.         $line = "\n";
  5318.         fprint( $fp, $line );
  5319.     }
  5320.  
  5321.     fclose( $fp );    
  5322.     return 1;
  5323. }
  5324.  
  5325. // This is what's called when the 'Text Dump' button is hit
  5326. // Just opens the fileBrowser, and uses 'bdeTextExport' as the callback
  5327. // (which is the preceeding func and is the guts of the text dump).
  5328. global proc bdeDumpTemplates()
  5329. {
  5330.     if (`about -evalVersion`) {
  5331.         // Because fopen and fprint are disabled in PLE, exporting of
  5332.         // character maps is not supported.
  5333.         //
  5334.         confirmDialog
  5335.             -m "Blind data text dump is not supported in Maya PLE."
  5336.             -b "Cancel" -db "Cancel";
  5337.         return;
  5338.     }
  5339.     
  5340.     fileBrowser "bdeTextExport" "DumpTo" "" 1;
  5341. }
  5342.  
  5343. // ViewSelected
  5344. //
  5345. // pretty simple tab that just displays the contents of the selected
  5346. // component/object. Note that we only handle one component.
  5347. // It'd be great to display all of the selected in a spreadsheet, but
  5348. // the spreadsheet ELF stuff is really not very extensible and doesn't 
  5349. // function well due to the fact that blind data on components aren't
  5350. // really 'attributes' in Maya's context.
  5351. // So, we just pick the lead selected and display that.
  5352. // Had also thought of displaying a user-defined locator on the selected
  5353. // components and having something along the lines of vcr controls to 
  5354. // advance or back up to different components, but i didn't have time
  5355. // to get this in there.
  5356. // So it's just this simple thing.
  5357.  
  5358. // Clear everything out
  5359. global proc bdeClearViewSelected()
  5360. {
  5361.     text -e -l "" bdeVsCompName;
  5362.  
  5363.     string $control;
  5364.     int $id, $dataCount;
  5365.  
  5366.     // Bug 150384 check exact type so we don't get subd blind data
  5367.     string $nodes[] = `ls -exactType blindDataTemplate`;
  5368.     int $numTypes = size( $nodes );
  5369.     if ( $numTypes == 0 )
  5370.         return;
  5371.     
  5372.     for ( $i = 0; $i < $numTypes; $i++ )
  5373.     {
  5374.         $id = getId( $nodes[$i] );
  5375.         $dataCount = getDataCount( $nodes[$i] );
  5376.         for ( $j = 0; $j < $dataCount; $j++ )
  5377.         {
  5378.             $control = "bdeVSValue" + $id + "_" + $j;
  5379.             // Originally had this set up as a grayed-out (disabled)
  5380.             // textField, but i was vetoed...
  5381.             // Bit hard to read on IRIX anyway.
  5382. //            textField -e -tx "" $control;
  5383.             if ( `text -q -ex $control` )
  5384.                 text -e -l "" $control;
  5385.         }
  5386.     }
  5387. }
  5388.  
  5389. // The guts - check the value of the 'lead component'
  5390. // for each of the existing blind data templates in the scene
  5391. // and set the text to be that value if it exists, empty string if
  5392. // not. Might do something like "N/A" or something if it doesn't exist
  5393. // if this is confusing.
  5394. // This gets called on a scriptJob as well as manually in a few places.
  5395. // Should ensure that the ViewSelected tab's been created already (see
  5396. // bdeRebuildViewSelected() below)
  5397. global proc bdeRefreshViewSelected()
  5398. {
  5399.     string $array[];
  5400.     string $control;
  5401.     string $value;
  5402.     string $name;
  5403.     string $dataType;
  5404.     string $compType;
  5405.     string $selected;
  5406.     string $sel[];
  5407.     int $id, $dataCount, $numTypes;
  5408.     
  5409.     bdeClearViewSelected();
  5410.  
  5411.     $sel = `ls -sl`;
  5412.  
  5413.     // There's nothing selected...
  5414.     if ( size($sel) == 0 )
  5415.         return;
  5416.  
  5417.     // $array[0] --> object name
  5418.     // $array[1] --> component type
  5419.     // $array[2] --> component id #
  5420.     $array = getSelectionComp( $sel[0] );
  5421.  
  5422.     // If this is the case, something is probably wrong...
  5423.     if ( $array[0] == "" )
  5424.         return;
  5425.  
  5426.     // Don't support vtxFace components, so we'll convert to the next
  5427.     // closest thing, verts.
  5428.     if ( $array[1] == "vtxFace" )
  5429.     {
  5430.         string $sl[] = `ls -sl`;
  5431.         string $buf[] = `polyListComponentConversion -tv $sl[0]`; 
  5432.         $array = getSelectionComp( $buf[0] );
  5433.     }
  5434.  
  5435.     // "*" means all are selected. We'll take the first element.
  5436.     if ( $array[2] == "*" )
  5437.         $array[2] = "0";
  5438.  
  5439.     $selected = $array[0] + "." + $array[1] + "[" + $array[2] + "]";
  5440.     if ( $array[1] == "f" )
  5441.         $compType = "face";
  5442.     else if ( $array[1] == "vtx" )
  5443.         $compType = "vertex";
  5444.     // If we got here, maybe the selected is a transform. Let's get the
  5445.     // associated shape and say it's an object.
  5446.     else if ( $array[1] == "" )
  5447.     {
  5448.         $selected = $array[0];
  5449.         string $kids[] = `listRelatives -s $selected`;
  5450.         if ( size( $kids ) )
  5451.             $selected = $kids[0];
  5452.         $compType = "object";
  5453.     }
  5454.     else
  5455.         $compType = "unknown";
  5456.  
  5457.     // We show what's selected (we better, since there's not a straightforward
  5458.     // way of knowing what your lead selection is...)
  5459.     text -e -l $selected bdeVsCompName;
  5460.  
  5461.     // Bug 150384 check exact type so we don't get subd blind data
  5462.     string $nodes[] = `ls -exactType blindDataTemplate`;    
  5463.     int $numTypes = size( $nodes );
  5464.     if ( $numTypes == 0 )
  5465.         return;
  5466.     
  5467.     for ( $i = 0; $i < $numTypes; $i++ )
  5468.     {
  5469.         $bdt = $nodes[$i];
  5470.         $id = getId( $bdt );
  5471.         $dataCount = getDataCount( $bdt );
  5472.         for ( $j = 0; $j < $dataCount; $j++ )
  5473.         {
  5474.             $dataType = getDataType( $bdt, $j );
  5475.             $name = getLongName( $bdt, $j );
  5476.  
  5477.             // Blind Data cmd now works for objects too
  5478.             $cmd = "polyQueryBlindData -id " + $id + " -at \"" + $compType + "\"";
  5479.             $cmd += " -ldn " + $name + " " + $selected;
  5480.             if ( $dataType == "int" || $dataType == "hex" || $dataType == "boolean" )
  5481.             {
  5482.                 int $vals[] = `eval( $cmd )`;
  5483.                 if ( size( $vals ) )
  5484.                     $value = $vals[0];
  5485.                 else
  5486.                     $value = "";
  5487.             }
  5488.             else if ( $dataType == "float" || $dataType == "double" )
  5489.             {
  5490.                 float $vals[] = `eval( $cmd )`;
  5491.                 if ( size( $vals ) )
  5492.                     $value = $vals[0];
  5493.                 else
  5494.                     $value = "";
  5495.             }
  5496.             else
  5497.             {
  5498.                 string $vals[] = `eval( $cmd )`;
  5499.                 if ( size( $vals ) )
  5500.                     $value = $vals[0];
  5501.                 else
  5502.                     $value = "";
  5503.             }
  5504.                 
  5505.             // If there's data and the type is hex, we'll convert to more
  5506.             // user-friendly hex string...
  5507.             if ( $dataType == "hex" && $value != "" )
  5508.             {
  5509.                 int $intVal = $value;
  5510.                 $value = intToHexString( $intVal );
  5511.             }
  5512.  
  5513.             $control = "bdeVSValue" + $id + "_" + $j;
  5514.             // These used to be textField, which i think make a little more sense,
  5515.             // but who am i to argue. Disabled textFields are a little hard to read
  5516.             // on IRIX, too.
  5517. //            textField -e -tx $value $control;
  5518.             if ( `text -q -ex $control` )
  5519.                 text -e -l $value $control;
  5520.             else
  5521.             {
  5522.                 // This shouldn't have happened, but we can handle it somewhat
  5523.                 // gracefully.
  5524.                 bdeRebuildViewSelected();
  5525.                 return;
  5526.             }
  5527.         }
  5528.     }
  5529. }
  5530.  
  5531. // Create the controls. Also calls bdeRefreshViewSelected,
  5532. // which fills them...
  5533. global proc bdeRebuildViewSelected()
  5534. {
  5535.     string        $control;
  5536.     string        $parent = "selectedLayout";
  5537.  
  5538.     // This should exist if the window does.
  5539.     if ( !`columnLayout -q -ex $parent` )
  5540.         return;
  5541.  
  5542.     // Delete the old stuff...
  5543.     string $children[] = `columnLayout -q -ca $parent`;
  5544.     for ( $child in $children )
  5545.     {
  5546.         deleteUI -lay $child;
  5547.     }
  5548.  
  5549.     // Bug 150384 check exact type so we don't get subd blind data
  5550.     string $nodes[] = `ls -exactType blindDataTemplate`;
  5551.     int $numTypes = size( $nodes );
  5552.     
  5553.     setParent $parent;
  5554.  
  5555.     for ( $i = 0; $i < $numTypes; $i++ )
  5556.     {
  5557.         string $bdt = $nodes[$i];
  5558.         int $id = getId( $bdt );
  5559.  
  5560.         rowColumnLayout -nc 3 -cw 1 120 -cw 2 80 -cw 3 80;
  5561.             text -l $id;
  5562.             int $dataCount = getDataCount( $bdt );
  5563.             for ( $j = 0; $j < $dataCount; $j++ )
  5564.             {
  5565.                 if ( $j != 0 )
  5566.                     separator -st "none";
  5567.                 $control = "bdeVSLongName" + $id + "_" + $j;
  5568.                 string $name = getLongName( $bdt, $j );
  5569.                 text -l $name $control;
  5570.                 $control = "bdeVSValue" + $id + "_" + $j;
  5571. //                textField -en false $control;
  5572.                 text -l "" $control;
  5573.             }
  5574.         setParent ..;
  5575.  
  5576.         columnLayout;
  5577.             separator -h 15 -style "none";
  5578.         setParent ..;
  5579.     }
  5580.  
  5581.     bdeRefreshViewSelected();
  5582. }
  5583. // End ViewSelected
  5584.  
  5585. // Force a rebuild of all of the UI.
  5586. // This happens on file->new/open,
  5587. // when the panel's torn off, etc.
  5588. // Pretty drastic, (as it chucks out all of user-defined
  5589. // data) (and slow!), so don't do it if not necessary.
  5590. global proc bdeForceRebuild()
  5591. {
  5592.     // Apply and DataTemplate
  5593.     bdeRebuildTextScrollLists();
  5594.     bdeRebuildPopups();
  5595.  
  5596.     // Apply:    
  5597.     bdeDeleteApplyUI();
  5598.  
  5599.     // Query/color
  5600. //    bdeRebuildPopups();
  5601.     bdeRebuildQueryColor();
  5602.  
  5603.     // View Selected
  5604.     bdeRebuildViewSelected();
  5605.  
  5606.     // Data Template
  5607.     bdeNewTemplate( true );
  5608. }
  5609.  
  5610.  
  5611. // This proc gets called before the panel/window is created 
  5612. global proc bdeCreateCallback( string $panel )
  5613. {
  5614.     // This next call turns false coloring on for the whole scene.
  5615.     // We found that this makes things hard to edit (because everything
  5616.     // in the scene is black) but if real colors are getting confused
  5617.     // with false color, you might turn this back on
  5618. //    polyColorBlindData -enableFalseColor 1;
  5619.  
  5620.     
  5621.     // Set smooth shading for the scene. We set it on the panel
  5622.     // 'withFocus' if this is a model editor, otherwise we set it
  5623.     // on the first modelEditor panel we find.
  5624.     string $currentPanel = `getPanel -withFocus`;
  5625.     if ( `getPanel -typeOf $currentPanel` == "modelPanel" )
  5626.         modelEditor -e -da "smoothShaded" $currentPanel;
  5627.     else
  5628.     {
  5629.         string $visPanels[] = `getPanel -vis`;
  5630.         for ( $panel in $visPanels )
  5631.         {
  5632.             if ( `getPanel -to $panel` == "modelPanel" )
  5633.             {
  5634.                 modelEditor -e -da "smoothShaded" $panel;
  5635.                 break;
  5636.             }
  5637.         }
  5638.     }
  5639.  
  5640.     //    Add support for the Context Sensitive Help Menu.
  5641.     //
  5642.     addContextHelpProc $panel "buildBlindDataEditorContextHelpItems";
  5643. }
  5644.  
  5645. // This proc gets called just before the panel is
  5646. // torn off or deleted
  5647. // We'll save pertinent data here in the form of optionVars
  5648. // so that next time the panel is opened the values get restored
  5649. global proc bdeRemoveCallback( string $panel )
  5650. {
  5651.     string $cmd = "optionVar ";
  5652.  
  5653.     string $bdt;
  5654.     string $ov;
  5655.     int $iv;
  5656.     string $sv;
  5657.     string $val;
  5658.     // Bug 150384 check exact type so we don't get subd blind data
  5659.     string $nodes[] = `ls -exactType blindDataTemplate`;
  5660.     int $ids[];
  5661.     int $numNodes = size( $nodes );
  5662.  
  5663.     optionVar -iv polyBdeNumTemplates $numNodes;
  5664.     
  5665.     for ( $i = 0; $i < $numNodes; $i++ )
  5666.     {
  5667.         $ids[$i] = getId( $nodes[$i] );
  5668.         $ov = "polyBdeTemplateId" + $i;
  5669.         optionVar -iv $ov $ids[$i];
  5670.  
  5671.         $dataCount = getDataCount( $nodes[$i] );
  5672.         for ( $j = 0; $j < $dataCount; $j++ )
  5673.         {
  5674.             $val = bdeGetControl( $nodes[$i], $j );
  5675.             if ( $val != "" )
  5676.             {
  5677.                 $ov = "polyBdeApplyVal" + $i + "_" + $j;
  5678.                 optionVar -sv $ov $val;
  5679.             }
  5680.         }
  5681.     }
  5682.  
  5683.     $iv = `checkBox -q -v bdeColorOnApply`;
  5684.     optionVar -iv polyBdeColorOnApply $iv;
  5685.  
  5686.     string $bdt = getSelectedApplyBdt();
  5687.     if ( $bdt != "" )
  5688.     {
  5689.         int $id = getId( $bdt );
  5690.         optionVar -iv polyBdeApplyId $id;
  5691.     }
  5692.  
  5693.     float $nc[] = `canvas -query -rgbValue bdeNoneColor`;
  5694.     float $cc[] = `canvas -query -rgbValue bdeClashColor`;
  5695.     float $oc[] = `canvas -query -rgbValue bdeOutOfRangeColor`;
  5696.     for ( $i = 0; $i < 3; $i++ )
  5697.     {
  5698.         optionVar -fva polyBdeNoneColor $nc[$i];
  5699.         optionVar -fva polyBdeClashColor $cc[$i];
  5700.         optionVar -fva polyBdeOutOfRangeColor $oc[$i];
  5701.     }
  5702.  
  5703.     int $numRows = getQcNumFilledRows();
  5704.     optionVar -iv polyBdeNumQcRows $numRows;
  5705.  
  5706.     for ( $i = 0; $i < $numRows; $i++ )
  5707.     {
  5708.         string $row = getQcFilledRow( $i );
  5709.         $iv = getQcEnable( $row );
  5710.         $ov = "polyBdeQcEnable" + $i;
  5711.         optionVar -iv $ov $iv;
  5712.  
  5713.         $sv = getQcType( $row );
  5714.         $ov = "polyBdeQcType" + $i;
  5715.         optionVar -sv $ov $sv;
  5716.  
  5717.         $iv = getQcValueEnable( $row );
  5718.         $ov = "polyBdeQcValueEnable" + $i;
  5719.         optionVar -iv $ov $iv;
  5720.  
  5721.         float $color[] = getQcMainColor( $row );
  5722.         $ov = "polyBdeQcMainColor" + $i;
  5723.         for ( $j = 0; $j < 3; $j++ )
  5724.             optionVar -fva $ov $color[$j];
  5725.  
  5726.         $color = getQcSaveColor( $row );
  5727.         $ov = "polyBdeQcSaveColor" + $i;
  5728.         for ( $j = 0; $j < 3; $j++ )
  5729.             optionVar -fva $ov $color[$j];
  5730.  
  5731.         if ( $iv == 1 )
  5732.         {
  5733.             string $selectType = getQcSelectType( $row );
  5734.             $ov = "polyBdeQcSelectType" + $i;
  5735.             optionVar -sv $ov $selectType;
  5736.  
  5737.             string $values[] = getQcValues( $row );
  5738.             int $numVals = size( $values );
  5739.  
  5740.             $ov = "polyBdeQcNumVals" + $i;
  5741.             optionVar -iv $ov $numVals;
  5742.  
  5743.             for ( $j = 0; $j < $numVals; $j++ )
  5744.             {
  5745.                 $ov = "polyBdeQcValue" + $i + "_" + $j;
  5746.                 optionVar -sv $ov $values[$j];
  5747.             }
  5748.         }
  5749.     }
  5750.     bdeKillViewSelectedSJ();
  5751. }
  5752.  
  5753. // This proc gets called when the panels is deleted
  5754. global proc bdeDeleteCallback( string $panel )
  5755. {
  5756.     // Turn off false coloring...
  5757.     polyColorBlindData -enableFalseColor 0;
  5758. }
  5759.  
  5760. // Called automatically on file -new or -open
  5761. // All of the blind data in the scene is probably
  5762. // invalid, so we'll make this call here to simplify
  5763. // clearing out all the controls.
  5764. global proc bdeInitCallback( string $panel )
  5765. {    
  5766.     bdeForceRebuild();
  5767. }
  5768.  
  5769. // Fills all of the controls (and creates them if they don't
  5770. // exist) with the data from the (saved) optionVars if the
  5771. // blind data templates defining the data exist in the scene.
  5772. global proc bdeRefreshFromOptionVars()
  5773. {
  5774.     global string $bdeQueryColorLayout;
  5775.     int $iv;
  5776.     string $sv;
  5777.     string $ov;
  5778.     int $dataCount;
  5779.     string $bdt;
  5780.     int $id;
  5781.  
  5782.     if ( `optionVar -ex polyBdeColorOnApply` )
  5783.     {
  5784.         $iv = `optionVar -q polyBdeColorOnApply`;
  5785.         checkBox -e -v $iv bdeColorOnApply;
  5786.     }
  5787.  
  5788.     if ( `optionVar -ex polyBdeNumTemplates` )
  5789.     {
  5790.         $numIds = `optionVar -q polyBdeNumTemplates`;
  5791.         for ( $i = 0; $i < $numIds; $i++ )
  5792.         {
  5793.             $ov = "polyBdeTemplateId" + $i;
  5794.             if ( `optionVar -ex $ov` )
  5795.             {
  5796.                 $id = `optionVar -q $ov`;
  5797.                 $bdt = getTemplateNameFromId( $id );
  5798.                 if ( $bdt != "" )
  5799.                 {
  5800.                     $dataCount = getDataCount( $bdt );
  5801.                     string $vals[];
  5802.                     for ( $j = 0; $j < $dataCount; $j++ )
  5803.                     {
  5804.                         $ov = "polyBdeApplyVal" + $i + "_" + $j;
  5805.                         if ( `optionVar -ex $ov` )
  5806.                         {
  5807.                             $sv = `optionVar -q $ov`;
  5808.                             $dataType = getDataType( $bdt, $j );
  5809.                             if ( $dataType == "hex" )
  5810.                                 $sv = intToHexString( $sv );
  5811.                             $vals[$j] = $sv;
  5812.                         }
  5813.                         else
  5814.                             $vals[$j] = "";
  5815.                     }
  5816.                     bdeSetControl( $bdt, $vals );
  5817.                 }
  5818.             }
  5819.         }
  5820.     }
  5821.  
  5822.     if ( `optionVar -ex polyBdeApplyId` )
  5823.     {
  5824.         $iv = `optionVar -q polyBdeApplyId`;
  5825.         $successfulSet = setSelectedApply( $iv );
  5826.         if ( $successfulSet )
  5827.             bdeRebuildApply();            
  5828.     }
  5829.  
  5830.     if ( `optionVar -ex polyBdeNumQcRows` )
  5831.     {
  5832.         int $numQcRows = `optionVar -q polyBdeNumQcRows`;
  5833.         for ( $i = 0; $i < $numQcRows; $i++ )
  5834.         {
  5835.             $ov = "polyBdeQcType" + $i;
  5836.             if ( `optionVar -ex $ov` )
  5837.             {
  5838.                 string $typestr = `optionVar -q $ov`;
  5839.                 $bdt = getTemplateNameFromTag( $typestr );
  5840.                 if ( $bdt == "" ) {
  5841.                     string $typeidstr = match("[0-9]*", $typestr);
  5842.                     if ( $typeidstr != "")
  5843.                         $bdt = getTemplateNameFromId( $typeidstr );
  5844.                 }
  5845.                 if ( $bdt != "" )
  5846.                 {
  5847.                     $row = getEmptyQcRow();                    
  5848.  
  5849.                     float $mainColor[] = { 0, 0, 0 };
  5850.                     float $saveColor[] = { 0, 0, 0 };
  5851.                     $ov = "polyBdeQcMainColor" + $i;
  5852.                     if ( `optionVar -ex $ov` )
  5853.                         $mainColor = `optionVar -q $ov`;
  5854.                     $ov = "polyBdeQcSaveColor" + $i;
  5855.                     if ( `optionVar -ex $ov` )
  5856.                         $saveColor = `optionVar -q $ov`;
  5857.                     setQcTypeAndColors( $row, $typestr, $mainColor, $saveColor );
  5858.  
  5859.                     $ov = "polyBdeQcEnable" + $i;
  5860.                     if ( `optionVar -ex $ov` )
  5861.                     {
  5862.                         $iv = `optionVar -q $ov`;
  5863.                         setQcEnable( $row, $iv );
  5864.                     }
  5865.  
  5866.                     $ov = "polyBdeQcValueEnable" + $i;
  5867.                     if ( `optionVar -ex $ov` )
  5868.                     {
  5869.                         $iv = `optionVar -q $ov`;
  5870.                         setQcValueEnable( $row, $iv );
  5871.                     }
  5872.  
  5873.                     if ( getQcValueEnable( $row ) )
  5874.                     {
  5875.                         $ov = "polyBdeQcSelectType" + $i;
  5876.                         if ( `optionVar -ex $ov` )
  5877.                         {
  5878.                             $sv = `optionVar -q $ov`;
  5879.                             setQcSelectType( $row, $sv );
  5880.                             toggleCollapseQcSelectType( $row, 0 );
  5881.                         }
  5882.  
  5883.                         $ov = "polyBdeQcNumVals" + $i;
  5884.                         if ( `optionVar -ex $ov` )
  5885.                         {
  5886.                             int $numVals = `optionVar -q $ov`;
  5887.                             for ( $j = 0; $j < $numVals; $j++ )
  5888.                             {
  5889.                                 $ov = "polyBdeQcValue" + $i + "_" + $j;
  5890.                                 if ( `optionVar -ex $ov` )
  5891.                                 {
  5892.                                     $sv = `optionVar -q $ov`;
  5893.                                     $dataType = getDataType( $bdt, $j );
  5894.                                     if ( $dataType == "hex" )
  5895.                                     {
  5896.                                         string $buffer[];
  5897.                                         int $numToks = `tokenize $sv " " $buffer`;
  5898.                                         if ( $numToks == 2 )
  5899.                                         {
  5900.                                             string $hexVal = intToHexString( $buffer[1] );
  5901.                                             $sv = $buffer[0] + " " + $hexVal;
  5902.                                         }
  5903.                                     }
  5904.                                     setQcValue( $row, $j, $sv );
  5905.                                 }
  5906.                             }
  5907.                         }
  5908.                     }
  5909.                 }
  5910.             }
  5911.         }
  5912.     }
  5913.  
  5914.     float $col[];
  5915.     if ( `optionVar -ex polyBdeNoneColor` )
  5916.     {
  5917.         $col = `optionVar -q polyBdeNoneColor`;
  5918.         canvas -edit -rgbValue $col[0] $col[1] $col[2] bdeNoneColor;
  5919.     }
  5920.     if ( `optionVar -ex polyBdeClashColor` )
  5921.     {
  5922.         $col = `optionVar -q polyBdeClashColor`;
  5923.         canvas -edit -rgbValue $col[0] $col[1] $col[2] bdeClashColor;
  5924.     }
  5925.     if ( `optionVar -ex polyBdeOutOfRangeColor` )
  5926.     {
  5927.         $col = `optionVar -q polyBdeOutOfRangeColor`;
  5928.         canvas -edit -rgbValue $col[0] $col[1] $col[2] bdeOutOfRangeColor;
  5929.     }
  5930.  
  5931.     // Here we delete all of the polyBde* optionVars, in case 
  5932.     // some have changed or whatever. They'll get saved again
  5933.     // when we exit anyway...
  5934.     string $vars[] = `optionVar -list`;
  5935.     int $foundOne = false;
  5936.     for ( $var in $vars )
  5937.     {
  5938.         if ( "polyBde" == `substring $var 1 7` )
  5939.         {
  5940.             $foundOne = true;
  5941.             optionVar -rm $var;
  5942.         }
  5943.         else if ( $foundOne )
  5944.             break;
  5945.     }
  5946. }
  5947.  
  5948. // Add callback is what gets called to generate the window,
  5949. // and it contains all of the code to create the controls...
  5950. global proc bdeAddCallback( string $panel )
  5951. {
  5952.     global int            $bdeCurrTab;
  5953.     global string        $bdeQueryColorLayout;
  5954.     global string        $bdeTPresetLayout;
  5955.  
  5956.     string $fullName = `scriptedPanel -q -ctl $panel`;
  5957.     string $buffer[];
  5958.     tokenize $fullName "|" $buffer;
  5959.     $isSeparate = `scriptedPanel -q -to $panel`;
  5960.     string $windowName = "";
  5961.     if ( $isSeparate )
  5962.         $windowName = $buffer[0];
  5963.  
  5964.     // The mainLayout is the whole window. It contains the
  5965.     // bdeMainTabLayout (which is the tabLayout you see when
  5966.     // you open the blindDataEditor) and the buttons at the bottom
  5967.     // (which are always there too)
  5968.     $mainLayout = `formLayout`;
  5969.         tabLayout -tabsVisible true -scrollable true
  5970.             -imw 10 -imh 10 -psc bdeRebuild bdeMainTabLayout;
  5971.  
  5972.             $applyLayout = `formLayout`;
  5973.  
  5974.                 $leftApply = `columnLayout -adj true -rs 20`;
  5975.                 if (`about -mac`)
  5976.                 {
  5977.                     textScrollList -w 100 -h 300 -numberOfRows 20 
  5978.                         -allowMultiSelection false
  5979.                         -sc bdeRebuildApply
  5980.                         bdeTypeList;
  5981.                 }
  5982.                 else
  5983.                 {    
  5984.                     textScrollList -w 100 -numberOfRows 20 
  5985.                         -allowMultiSelection false
  5986.                         -sc bdeRebuildApply
  5987.                         bdeTypeList;
  5988.                 }
  5989.  
  5990.                     columnLayout -adj true;
  5991.                         button -l "Paint values" -c bdePaintValues;
  5992.                         // Uncomment out the next call and the Paint Values button
  5993.                         // won't bring up the Attribute Paint tool window (which
  5994.                         // might get quite annoying)
  5995.                         // Note that you can't bring up the attribute paint
  5996.                         // tool from the main menu, however - it resets the values and
  5997.                         // will probably mess everything up)
  5998. //                        button -l "Paint options" -c bdePaintOptions;
  5999.                     setParent ..;
  6000.  
  6001.                     checkBox -v 0 -l "Color data on apply" -al "left" bdeColorOnApply;
  6002.  
  6003.                 setParent ..; // $leftApply
  6004.  
  6005.                 tabLayout -tabsVisible false -cr true -imw 10 -imh 10 
  6006.                     bdeSingleApplyLayout;
  6007.                 setParent ..;
  6008.  
  6009.             setParent ..; // $applyLayout
  6010.  
  6011.             formLayout -e
  6012.                 -af $leftApply "top" 10
  6013.                 -af $leftApply "left" 10
  6014.                 -an $leftApply "bottom" 
  6015.  
  6016.                 -ac bdeSingleApplyLayout "left" 10 $leftApply
  6017.                 -af bdeSingleApplyLayout "top" 10
  6018.                 -af bdeSingleApplyLayout "bottom" 10
  6019.                 -af bdeSingleApplyLayout "right" 10
  6020.                 $applyLayout;
  6021.  
  6022.             $qcLayout = `columnLayout`;
  6023.                 if (!`uiTemplate -exists bdeQcMainLineTemplate`)
  6024.                     uiTemplate bdeQcMainLineTemplate;
  6025.                 if ( !`uiTemplate -exists bdeQcColorTemplate` )
  6026.                     uiTemplate bdeQcColorTemplate;
  6027.                 
  6028.                 // Create the template so that we don't have to define these
  6029.                 // things everywhere
  6030.                 rowLayout -defineTemplate bdeQcMainLineTemplate 
  6031.                     -nc 8
  6032.                     -cw 1 25 // Check
  6033.                     -cw 2 110 // Type
  6034.                     -cw 3 25 //-cat 4 "right" 5 // Check
  6035.                     -cw 4 90 // Attr tag
  6036.                     -cw 5 100 // Value
  6037.                     -cw 6 5 //-cat 7 "left" 0 // Button
  6038.                     -cw 7 80 // Canvas
  6039.                     -cw 8 80; // Delete button
  6040.                 rowColumnLayout -defineTemplate bdeQcColorTemplate
  6041.                     -nc 3
  6042.                     -cw 1 25
  6043.                     -cw 2 250
  6044.                     -cw 3 100;
  6045.  
  6046.                 rowLayout -nc 2 -cw 1 120 -cw 2 200 -cat 1 "left" 10;
  6047.                     button -l "New" -c "bdeNewQcRow";
  6048.                     separator -st "none";
  6049.                 setParent ..;
  6050.  
  6051.                 columnLayout;
  6052.                     separator -w 400 -h 20 -style "out";
  6053.                 setParent ..;
  6054.  
  6055.                 // Could have used other rowLayout templates for the 
  6056.                 // queryColorHeader as well as the clash color and
  6057.                 // out of range color so that we don't have to use all
  6058.                 // of these separators. There are only three static ones
  6059.                 // here, however, so that's not too big of a deal for 
  6060.                 // the ease of layout control...
  6061.                 rowLayout -ut bdeQcMainLineTemplate bdeQueryColorHeader;
  6062.                     separator -st "none"; // Check
  6063.                     text -l "Tag/Id";
  6064.                     separator -st "none"; // A check
  6065.                     text -l "Long Name";
  6066.                     text -l "Value";
  6067.                     separator -st "none"; // Canvas
  6068.                     separator -st "none"; // A button
  6069.                     separator -st "none"; // A button to delete this row
  6070.                 setParent ..;                    
  6071.  
  6072.                 $bdeQueryColorLayout = `columnLayout bdeQueryColorLayout`;
  6073.                 setParent ..;
  6074.  
  6075.                 separator -h 30 -st "none";
  6076.  
  6077.                 rowLayout -ut bdeQcMainLineTemplate;
  6078.                     separator -st "none";
  6079.                     text -l "Clash color";
  6080.                     separator -st "none";
  6081.                     separator -st "none";
  6082.                     separator -st "none";
  6083.                     separator -st "none";
  6084.                     canvas -width 70 -height 25 -rgbValue 0 1 1 
  6085.                         -pc ( "bdeChangeNamedCanvas bdeClashColor" ) bdeClashColor;
  6086.                 setParent ..;
  6087.  
  6088.                 separator -h 10 -st "none";
  6089.  
  6090.                 rowLayout -ut bdeQcMainLineTemplate;
  6091.                     separator -st "none";
  6092.                     text -l "Out of range color";
  6093.                     separator -st "none";
  6094.                     separator -st "none";
  6095.                     separator -st "none";
  6096.                     separator -st "none";
  6097.                     canvas -width 70 -height 25 -rgbValue 1 1 0 
  6098.                         -pc ( "bdeChangeNamedCanvas bdeOutOfRangeColor" ) bdeOutOfRangeColor;
  6099.                 setParent ..;
  6100.  
  6101.                 separator -h 10 -st "none";
  6102.  
  6103.                 rowLayout -ut bdeQcMainLineTemplate;
  6104.                     separator -st "none";
  6105.                     text -l "'None' color";
  6106.                     separator -st "none";
  6107.                     separator -st "none";
  6108.                     separator -st "none";
  6109.                     separator -st "none";
  6110.                     canvas -width 70 -height 25 -rgbValue 0 0 0 
  6111.                         -pc ( "bdeChangeNamedCanvas bdeNoneColor" ) bdeNoneColor;
  6112.                 setParent ..;                    
  6113.  
  6114.             setParent ..; // $qcLayout
  6115.  
  6116.             columnLayout -adj true bdeViewSelectedLayout;
  6117.                 columnLayout -adj true bdeVSTempLayout;
  6118.                 rowLayout -nc 2 -cw 1 160 -cw 2 200;
  6119.                     text -l "Displayed component:";
  6120.                     text -l "" bdeVsCompName;
  6121.                     // Don't need this so much now that i found the script job
  6122.                     // on selectionChange, but could prove useful if things
  6123.                     // aren't working as expected...
  6124. //                        button -l "Refresh" -c "bdeRefreshViewSelected";
  6125.                 setParent ..;
  6126.                 setParent ..;
  6127.  
  6128.                 separator -w 400 -h 10 -style "in";
  6129.  
  6130.                 columnLayout -adj true selectedLayout;
  6131.                 setParent ..;
  6132.             setParent ..; // bdeViewSelectedLayout
  6133.  
  6134.             formLayout bdeDataTemplateLayout;
  6135.                 formLayout -w 150 leftLayout;
  6136.                 
  6137.             if (`about -mac`)
  6138.             {
  6139.                     textScrollList -w 100 -h 300 -numberOfRows 20 
  6140.                         -allowMultiSelection false
  6141.                         -sc bdeTNameListChange
  6142.                         bdeTemplateList;
  6143.             }
  6144.             else
  6145.             {
  6146.                     textScrollList -w 100 -numberOfRows 20 
  6147.                         -allowMultiSelection false
  6148.                         -sc bdeTNameListChange
  6149.                         bdeTemplateList;
  6150.             }
  6151.  
  6152.                     columnLayout -w 150 leftButtonLayout;
  6153.                         button -w 80 -l "New" -c ( "bdeNewTemplate 1" ) bdeNewTemplateButton;
  6154.                         button -w 80 -l "Edit" -c bdeEditTemplate bdeEditTemplateButton;
  6155.                         button -w 80 -l "Save" -c bdeSaveTemplate bdeSaveTemplateButton;
  6156.  
  6157.                         separator -h 20 -st "none";
  6158.                         button -w 80 -l "Export" -c bdeExportTemplates;
  6159.                         button -w 80 -l "Text Dump" -c bdeDumpTemplates;
  6160.  
  6161.                     setParent ..;
  6162.                 setParent ..; // leftLayout
  6163.  
  6164.                 formLayout -e
  6165.                     -af bdeTemplateList "left" 0
  6166.                     -af bdeTemplateList "top" 0
  6167.                     -af bdeTemplateList "right" 0
  6168.                     -an bdeTemplateList "bottom"
  6169.  
  6170.                     -ac leftButtonLayout "top" 20 bdeTemplateList
  6171.                     -af leftButtonLayout "left" 10
  6172.                     -an leftButtonLayout "right"
  6173.                     -af leftButtonLayout "bottom" 10
  6174.                     leftLayout;
  6175.  
  6176.                 columnLayout -adj true -rs 5 rightLayout;
  6177.                     rowColumnLayout -nc 2;
  6178.                         text -l "Id";
  6179.                         intField -cc bdeTIdChange bdeTTypeId;
  6180.  
  6181.                         text -l "Name";
  6182.                         textField bdeTTypeName;
  6183.                     setParent ..;
  6184.  
  6185.                     formLayout bdeTCommonLayout;
  6186.                         rowColumnLayout -nc 2 bdeTCommonRcLayout;
  6187.                             text -l "Association type";
  6188.                             optionMenu bdeTAssocType;
  6189.                                 menuItem "any";
  6190.                                 menuItem "face";
  6191.                                 menuItem "vertex";
  6192.                                 menuItem "object";
  6193.  
  6194.                             separator -st "none";
  6195.                             checkBox -l "Free set" -v 1 
  6196.                                 -cc bdeTFreeSetChanged bdeTFreeSet;
  6197.                         setParent ..;
  6198.  
  6199.                         button -vis true -w 75 -l "New Attr" 
  6200.                             -c "bdeNewDescriptor" bdeNewDescriptorButton;
  6201.                     setParent ..;
  6202.  
  6203.                     formLayout -e
  6204.                         -af bdeTCommonRcLayout "top" 0
  6205.                         -af bdeTCommonRcLayout "left" 0
  6206.                         -an bdeTCommonRcLayout "right" 
  6207.                         -an bdeTCommonRcLayout "bottom"
  6208.  
  6209.                         -ac bdeNewDescriptorButton "top" 0 bdeTCommonRcLayout
  6210.                         -an bdeNewDescriptorButton "bottom"
  6211.                         -af bdeNewDescriptorButton "left" 0
  6212.                         -an bdeNewDescriptorButton "right"
  6213.                         bdeTCommonLayout;
  6214.  
  6215.                     columnLayout -adj true bdeTDescriptorLayout;
  6216.                         bdeTBuildDescriptor( 0 );
  6217.                         bdeTBuildDescriptor( 1 );
  6218.                         bdeTBuildDescriptor( 2 );
  6219.                     setParent ..;
  6220.  
  6221.                     bdeTOpenDescriptor( 0 );
  6222.  
  6223.                     formLayout presetFormLayout;
  6224.                         button -vis true -w 75 -l "New Preset" 
  6225.                             -al "center" -c "bdeTNewPreset" bdeNewPresetButton;
  6226.  
  6227.                         $bdeTPresetLayout = `columnLayout -adj true`;                            
  6228.                         setParent ..;
  6229.                     setParent ..;
  6230.  
  6231.                     formLayout -e
  6232.                         -af bdeNewPresetButton "top" 0
  6233.                         -af bdeNewPresetButton "left" 0
  6234.                         -an bdeNewPresetButton "right"
  6235.                         -ac bdeNewPresetButton "bottom" 0 $bdeTPresetLayout
  6236.  
  6237.                         -af $bdeTPresetLayout "left" 0
  6238.                         -an $bdeTPresetLayout "top"
  6239.                         -af $bdeTPresetLayout "bottom" 0
  6240.                         -af $bdeTPresetLayout "right" 0
  6241.                         presetFormLayout;
  6242.                 setParent ..; // rightLayout
  6243.  
  6244.                 formLayout -e
  6245.                     -af leftLayout "left" 5
  6246.                     -af leftLayout "top" 5
  6247.                     -an leftLayout "right"
  6248.                     -af leftLayout "bottom" 5
  6249.  
  6250.                     -ac rightLayout "left" 15 leftLayout
  6251.                     -af rightLayout "top" 5
  6252.                     -af rightLayout "right" 5
  6253.                     -af rightLayout "bottom" 5
  6254.                     bdeDataTemplateLayout;
  6255.             setParent ..; // bdeDataTemplateLayout
  6256.  
  6257.             tabLayout -e -tabLabel $applyLayout "Apply" 
  6258.                     -tabLabel $qcLayout "Color/Query" 
  6259.                     -tabLabel bdeViewSelectedLayout "View"
  6260.                     -tabLabel bdeDataTemplateLayout "Type Editor"
  6261.                 bdeMainTabLayout;
  6262.  
  6263.         setParent ..; // bdeMainTabLayout
  6264.  
  6265.         $bottomCommonLayout = `formLayout`;
  6266.             button -en true -rs false -label "Apply" -c "bdeApplyData" bdeApplyButton;
  6267.             button -en false -rs false -label "Set Color" -c "bdeColor" bdeSetColorButton;
  6268.             button -en false -rs false -label "Query" -c "bdeQuery" bdeQueryButton;
  6269.             button -label "Remove Color" -rs false -c "bdeRemoveColor" bdeRemColorButton;
  6270.             if ( $isSeparate )
  6271.                 button -label "Close" -rs false -c ( "deleteUI " + $windowName ) bdeCloseButton;
  6272.         setParent ..;
  6273.  
  6274.         // Stole the following code from the polyConstraintWindow (which is a panel too).
  6275.         // Gist of it is that if the panel is not torn-off, there's no cancel button.
  6276.         // We also want to align the buttons evenly along the bottom row...
  6277.  
  6278.         //  Force the buttons to have a common width, this will not only
  6279.         //  look better but also allow the buttons to be centred in the
  6280.         //  window.
  6281.         int $divisions = `formLayout -query -numberOfDivisions $bottomCommonLayout`;
  6282.         if ($isSeparate)
  6283.         {
  6284.             int $left   = $divisions / 5;    // Left division
  6285.             int $lmiddle = $divisions * 2/5;    // LMiddle division
  6286.             int $rmiddle = $divisions * 3/5; // RMiddle division
  6287.             int $right  = $divisions * 4/5;    // Right division
  6288.             formLayout -e
  6289.                 -af bdeApplyButton   "top"    0
  6290.                 -af bdeApplyButton   "bottom" 0
  6291.                 -af bdeApplyButton   "left"   0
  6292.                 -ac bdeApplyButton   "right"  0 bdeSetColorButton
  6293.             
  6294.                 -af bdeSetColorButton   "top"    0
  6295.                 -af bdeSetColorButton   "bottom" 0
  6296.                 -ap bdeSetColorButton   "left"   0 $left
  6297.                 -ap bdeSetColorButton   "right"  0 $lmiddle
  6298.             
  6299.                 -af bdeQueryButton "top"    0
  6300.                 -af bdeQueryButton "bottom" 0
  6301.                 -ap bdeQueryButton "left"   0 $lmiddle
  6302.                 -ap bdeQueryButton "right"  0 $rmiddle
  6303.  
  6304.                 -af bdeRemColorButton "top"        0
  6305.                 -af bdeRemColorButton "bottom"    0
  6306.                 -ap bdeRemColorButton "left"    0 $rmiddle
  6307.                 -ap bdeRemColorButton "right"    0 $right
  6308.  
  6309.                 -af bdeCloseButton  "top"    0
  6310.                 -af bdeCloseButton  "bottom" 0
  6311.                 -ac bdeCloseButton  "left"   0 bdeRemColorButton
  6312.                 -af bdeCloseButton  "right"  0
  6313.                 $bottomCommonLayout;
  6314.         }
  6315.         else 
  6316.         {
  6317.             int $left  = $divisions / 4;    // Left division
  6318.             int $middle = $divisions / 2;    // middle division
  6319.             int $right = $divisions * 3/4;    // Right division
  6320.             formLayout -e
  6321.                 -af bdeApplyButton   "top"    0
  6322.                 -af bdeApplyButton   "bottom" 0
  6323.                 -af bdeApplyButton   "left"   0
  6324.                 -ac bdeApplyButton   "right"  0 bdeSetColorButton
  6325.  
  6326.                 -af bdeSetColorButton   "top"    0
  6327.                 -af bdeSetColorButton   "bottom" 0
  6328.                 -ap bdeSetColorButton   "left"   0 $left
  6329.                 -ap bdeSetColorButton   "right"  0 $middle
  6330.  
  6331.                 -af bdeQueryButton "top"    0
  6332.                 -af bdeQueryButton "bottom" 0
  6333.                 -ap bdeQueryButton "left"  0 $middle
  6334.                 -ap bdeQueryButton "right"   0 $right
  6335.  
  6336.                 -af bdeRemColorButton "top"        0
  6337.                 -af bdeRemColorButton "bottom"    0
  6338.                 -ac bdeRemColorButton "left"    0 bdeQueryButton
  6339.                 -af bdeRemColorButton "right"    0
  6340.                 $bottomCommonLayout;
  6341.         }
  6342.  
  6343.     formLayout -e
  6344.         -af bdeMainTabLayout "left" 0
  6345.         -af bdeMainTabLayout "top" 10
  6346.         -ac bdeMainTabLayout "bottom" 0 $bottomCommonLayout
  6347.         -af bdeMainTabLayout "right" 0
  6348.  
  6349.         -af $bottomCommonLayout "left" 0
  6350.         -af $bottomCommonLayout "right" 0
  6351.         -an $bottomCommonLayout "top"
  6352.         -af $bottomCommonLayout "bottom" 0
  6353.         $mainLayout;    
  6354.  
  6355.  
  6356.     // set the menu bar visibility (can be turned off from UIPrefs)
  6357.     //
  6358.     int $menusOkayInPanels = `optionVar -q allowMenusInPanels`;
  6359.     panel -e -mbv $menusOkayInPanels $panel;
  6360.  
  6361.     bdeForceRebuild();
  6362.     bdeRefreshFromOptionVars();
  6363. }
  6364.  
  6365. // From the apply tab again...
  6366.  
  6367. // If we're 'Apply'ing to objects, we're applying dynamic attributes
  6368. // and we have to do things a bit differently
  6369. global proc bdeApplyDynamicAttr( string $bdt, string $applyType )
  6370. {
  6371.     string $data[];
  6372.     string $dataType[];
  6373.     string $longName[];
  6374.     string $shortName[];
  6375.     string $control;
  6376.     string $genericType;
  6377.     string $setAttrTypeString;
  6378.     string $addAttrTypeString;
  6379.     string $cmd = "setAttr ";
  6380.     // We use setAttr instead of polyBlindData command...
  6381.     
  6382.     int $dataCount = getDataCount( $bdt );
  6383.     int $id = getId( $bdt );
  6384.  
  6385.     string $rawSelList[] = `ls -sl`;
  6386.     string $selList[];
  6387.     string $nodeList[];
  6388.     string $sep[];
  6389.  
  6390.     // We want all the *shapes* from the selection.
  6391.     // Often the selection uses the name of the transform,
  6392.     // so we use the listRelatives -shapes command to get the child
  6393.     // shapes.
  6394.     for ( $i = 0, $j = 0; $i < size( $rawSelList ); $i++ )
  6395.     {
  6396.         $sep = getSelectionComp( $rawSelList[$i] );
  6397.         $nodeType = `nodeType $sep[0]`;
  6398.         if ( "transform" == $nodeType )
  6399.         {
  6400.             string $children[] = `listRelatives -shapes $sep[0]`;
  6401.             for ( $child in $children )
  6402.             {
  6403.                 $selList[$j++] = $child;
  6404.             }
  6405.         }
  6406.         else
  6407.         {
  6408.             $selList[$j++] = $sep[0];
  6409.         }
  6410.     }
  6411.  
  6412.     // Filter out duplicates.
  6413.     for ( $i = 0, $j = 0; $i < size( $selList ); $i++ )
  6414.     {
  6415.         int $foundIt = false;
  6416.         for ( $k = 0; $k < size( $nodeList ); $k++ )
  6417.         {
  6418.             if ( $nodeList[$k] == $selList[$i] )
  6419.             {
  6420.                 $foundIt = true;
  6421.                 break;
  6422.             }
  6423.         }
  6424.         
  6425.         if ( !$foundIt )
  6426.             $nodeList[$j++] = $selList[$i];
  6427.     }
  6428.  
  6429.     for ( $i = 0; $i < $dataCount; $i++ )
  6430.     {
  6431.         $control = "bdeLongDataName" + $id + "_" + $i;
  6432.         $longName[$i] = `text -q -l $control`;
  6433. //        $control = "bdeShortDataName" + $id + "_" + $i;
  6434. //        $shortName[$i] = `text -q -l $control`;
  6435.         $shortName[$i] = getShortName( $bdt, $i );
  6436.  
  6437.         $control = "bdeDataType" + $id + "_" + $i;
  6438.         $dataType[$i] = `text -q -l $control`;
  6439.         $control =  "bdeDataValue" + $id + "_" + $i;
  6440.         $data[$i] = bdeGetControl( $bdt, $i );
  6441.     }
  6442.     
  6443.     // We have to handle the case of the data being there already, and thus
  6444.     // we're just going to modify it, or we have to create the attribute.
  6445.     for ( $nodeIndex = 0; $nodeIndex < size( $nodeList ); $nodeIndex++ )
  6446.     {
  6447.         string $node = $nodeList[$nodeIndex];        
  6448.  
  6449.         // We create/modify each attribute one by one instead of handling special
  6450.         // cases such as double2 or int3's.
  6451.         // This is more consistent with the component blind data also.
  6452.         for ( $i = 0; $i < $dataCount; $i++ )
  6453.         {
  6454.             $genericType = getGenericDataType( $dataType[$i] );
  6455.             if ( $genericType == "string" )
  6456.             {
  6457.                 $addAttrTypeString = " -dt \"string\" ";
  6458.                 $setAttrTypeString = " -type \"string\" ";
  6459.                 $data[$i] = "\"" + $data[$i] + "\"";
  6460.             }
  6461.             else
  6462.             {
  6463.                 $addAttrTypeString = " -at \"" + $genericType + "\" ";
  6464.                 $setAttrTypeString = "";
  6465.             }
  6466.  
  6467.             if ( !`attributeQuery -n $node -ex $longName[$i]` &&
  6468.                  !`attributeQuery -n $node -ex $shortName[$i]` )
  6469.             {
  6470.                 // The attributes don't exist.
  6471.  
  6472.                 // If they're trying to scale or offset the data we don't 
  6473.                 // let them, because it's not there!
  6474.                 if ( $applyType != "Absolute" )
  6475.                     continue;
  6476.  
  6477.                 // Create the attribute
  6478.                 $cmd = "addAttr -ln " + $longName[$i] + " -sn " 
  6479.                     + $shortName[$i] + $addAttrTypeString + $node;
  6480. //                print( $cmd + "\n" );
  6481.                 eval( $cmd );
  6482.             }
  6483.             else
  6484.             {
  6485.                 // The attribute exists in one or both of the names we
  6486.                 // think it should be. We check to make sure it's our attribute
  6487.                 // and not some internal one or previously-defined one...
  6488.                 if ( `attributeQuery -n $node -ex $longName[$i]` )
  6489.                 {
  6490.                     if ( `attributeQuery -n $node -i $longName[$i]` || 
  6491.                          `attributeQuery -n $node -h $longName[$i]` )
  6492.                     {
  6493.                         print( "// Attribute " + $longName[$i] + " exists and is internal or hidden\n" );
  6494.                         print( "// Skipping...\n" );
  6495.                         continue;
  6496.                     }                    
  6497.                     $cmd = "getAttr -type " + $node + "." + $longName[$i];
  6498.                     $type = `eval( $cmd )`;
  6499.                     if ( $type != $genericType )
  6500.                     {
  6501.                         print( "// Attribute " + $longName[$i] + " exists and is of a different type than specified\n" );
  6502.                         print( "// Skipping...\n" );
  6503.                         continue;
  6504.                     }
  6505.                 }
  6506.                 if ( `attributeQuery -n $node -ex $shortName[$i]` )
  6507.                 {
  6508.                     if ( `attributeQuery -n $node -i $shortName[$i]` || 
  6509.                          `attributeQuery -n $node -h $shortName[$i]` )
  6510.                     {
  6511.                         print( "// Attribute " + $shortName[$i] + " exists and is internal or hidden\n" );
  6512.                         print( "// Skipping...\n" );
  6513.                         continue;
  6514.                     }                    
  6515.                     $cmd = "getAttr -type " + $node + "." + $shortName[$i];
  6516.                     $type = `eval( $cmd )`;
  6517.                     if ( $type != $genericType )
  6518.                     {
  6519.                         print( "// Attribute " + $shortName[$i] + " exists and is of a different type than specified\n" );
  6520.                         print( "// Skipping...\n" );
  6521.                         continue;
  6522.                     }
  6523.                 }
  6524.             }
  6525.             if ( $applyType == "Absolute" )
  6526.             {
  6527.                 $cmd = "setAttr " + $setAttrTypeString + $node + "." + $longName[$i] + " " + $data[$i];
  6528. //                print( $cmd + "\n" );
  6529.                 eval( $cmd );
  6530.             }
  6531.             else 
  6532.             {
  6533.                 // This shouldn't even happen, but just in case
  6534.                 if ( $genericType == "string" || $genericType == "boolean" )
  6535.                     continue;
  6536.  
  6537.                 float $floatVal;
  6538.                 int $intVal;
  6539.                 $cmd = "getAttr " + $setAttrTypeString + $node + "." + $longName[$i];
  6540.                 if ( $genericType == "double" )
  6541.                     $floatVal = `eval( $cmd )`;
  6542.                 else if ( $genericType == "int" )
  6543.                     $intVal = `eval( $cmd )`;
  6544.  
  6545.                 float $newFloatVal;
  6546.                 int $newIntVal;                
  6547.                 if ( $applyType == "Offset" )
  6548.                 {
  6549.                     $controlName = "bdeDataOffset" + $id + "_" + $i;
  6550.                     if ( $genericType == "double" )
  6551.                     {
  6552.                         float $offset = `floatSliderGrp -q -v $controlName`;
  6553.                         $newFloatVal = $floatVal + $offset;
  6554.                     }
  6555.                     else
  6556.                     {
  6557.                         int $offset = `intSliderGrp -q -v $controlName`;
  6558.                         $newIntVal = $intVal + $offset;
  6559.                     }
  6560.                 }
  6561.                 else
  6562.                 {                    
  6563.                     $controlName = "bdeDataScale" + $id + "_" + $i;
  6564.                     float $scale = `floatSliderGrp -q -v $controlName`;
  6565.                     if ( $genericType == "double" )
  6566.                         $newFloatVal = $floatVal * $scale;
  6567.                     else
  6568.                         $newIntVal = round( $intVal * $scale );
  6569.                 }
  6570.                 int $ranged = getRanged( $bdt, $i );
  6571.                 if ( $ranged )
  6572.                 {
  6573.                     // Here's where we clamp the values if the attr's ranged.
  6574.                     // If you don't want the data clamped, remove these checks
  6575.                     float $min = getMinVal( $bdt, $i );
  6576.                     float $max = getMaxVal( $bdt, $i );
  6577.                     if ( $genericType == "double" )
  6578.                     {
  6579.                         if ( $newFloatVal > $max )
  6580.                             $newFloatVal = $max;
  6581.                         if ( $newFloatVal < $min )
  6582.                             $newFloatVal = $min;
  6583.                     }
  6584.                     else
  6585.                     {
  6586.                         if ( $newIntVal > $max )
  6587.                             $newIntVal = $max;
  6588.                         if ( $newIntVal < $min )
  6589.                             $newIntVal = $min;
  6590.                     }
  6591.                 }
  6592.  
  6593.                 $cmd = "setAttr " + $setAttrTypeString + $node + "." + $longName[$i] + " ";
  6594.                 if ( $genericType == "double" )
  6595.                     $cmd += $newFloatVal;
  6596.                 else
  6597.                     $cmd += $newIntVal;
  6598. //                print( $cmd + "\n" );
  6599.                 eval( $cmd );
  6600.             }
  6601.         }
  6602.     }
  6603. }
  6604.  
  6605. // Apply the absolute data
  6606. // The polyBlindData command works on the selection list by default, 
  6607. // and we're assuming here that that has been converted if it's going
  6608. // to be.
  6609. proc applyAbsolute( string $bdt )
  6610. {
  6611.     int $id = getId( $bdt );
  6612.     string $control = "bdeAssocType" + $id;
  6613.     string $assocType = `optionMenu -q -v $control`;
  6614.  
  6615.     string $baseCmd = "polyBlindData -id " + $id;
  6616.     $baseCmd += " -associationType \"" + $assocType + "\"";
  6617.  
  6618.     if( $assocType == "object")
  6619.         $baseCmd += " -shape ";
  6620.  
  6621.     int $dataCount = getDataCount( $bdt );
  6622.     for ( $i = 0; $i < $dataCount; $i++ )
  6623.     {
  6624.         string $cmd = $baseCmd;
  6625.         string $longName = getLongName( $bdt, $i );
  6626.         string $dataType = getDataType( $bdt, $i );
  6627.         string $dataTypeFlag = getDataTypeFlag( $dataType );
  6628.         $cmd += " -longDataName \"" + $longName + "\"";
  6629.         $cmd += " " + $dataTypeFlag;
  6630.         // The command can handle the data in the form of a string
  6631.         // which makes things a bit easier on us (no conversions!)
  6632.         string $data = bdeGetControl( $bdt, $i );
  6633.         if ( $dataType == "string" || $dataType == "binary" )
  6634.             $cmd += " \"" + $data + "\"";
  6635.         else
  6636.             $cmd += " " + $data;
  6637.         
  6638.         print( $cmd + "\n" );
  6639.         eval ( $cmd );
  6640.     }
  6641. }
  6642.  
  6643. // Apply scale or offset values. This is a bit trickier, because we've
  6644. // got to get the data first. We use the polyQueryBlindData command
  6645. // and if the data's not there we skip it.
  6646. proc applyRelative( string $bdt, string $applyType, string $assocType )
  6647. {
  6648.     string $dataType;
  6649.     string $control;
  6650.     int $id = getId( $bdt );
  6651.     int $dataCount = getDataCount( $bdt );
  6652.  
  6653.     for ( $i = 0; $i < $dataCount; $i++ )
  6654.     {
  6655.         string $dataType = getDataType( $bdt, $i );
  6656.         string $attrName = getLongName( $bdt, $i );
  6657.         if ( $dataType == "string" || $dataType == "binary" || 
  6658.              $dataType == "boolean" || $dataType == "hex" )
  6659.              continue;
  6660.  
  6661.         string $cmd = "polyQueryBlindData -id " + $id;
  6662.         $cmd += " -ldn " + $attrName + " -sc";
  6663.         print( $cmd + "\n" );
  6664.         string $sc[] = `eval( $cmd )`;
  6665.         for ( $j = 0; $j < size( $sc ); $j++ )
  6666.         {
  6667.             $attr = $sc[$j++];
  6668.             $val = $sc[$j];
  6669.  
  6670.             string $buf[];
  6671.             int $numTokens = tokenize( $attr, ".", $buf );
  6672.             if ( $numTokens != 3 )
  6673.                 continue;
  6674.             $comp = $buf[0] + "." + $buf[1];
  6675.  
  6676.             float $floatVal, $newFloatVal;
  6677.             int $intVal, $newIntVal;
  6678.             if ( $dataType == "double" )
  6679.                 $floatVal = $val;
  6680.             else
  6681.                 $intVal = $val;
  6682.             if ( $applyType == "Offset" )
  6683.             {
  6684.                 $control = "bdeDataOffset" + $id + "_" + $i;
  6685.                 if ( $dataType == "double" )
  6686.                 {
  6687.                     float $offset = `floatSliderGrp -q -v $control`;
  6688.                     $newFloatVal = $floatVal + $offset;
  6689.                 }
  6690.                 else
  6691.                 {
  6692.                     int $offset = `intSliderGrp -q -v $control`;
  6693.                     $newIntVal = $intVal + $offset;
  6694.                 }
  6695.             }
  6696.             else
  6697.             {
  6698.                 $control = "bdeDataScale" + $id + "_" + $i;
  6699.                 float $scale = `floatSliderGrp -q -v $control`;
  6700.                 if ( $dataType == "double" )
  6701.                     $newFloatVal = $floatVal * $scale;
  6702.                 else
  6703.                     $newIntVal = round( $intVal * $scale );
  6704.             }
  6705.             int $ranged = getRanged( $bdt, $attrName );
  6706.             if ( $ranged )
  6707.             {
  6708.                 // This is where the clamping happens for poly component
  6709.                 // blind data. Comment out these checks if you don't want
  6710.                 // the values to be clamped at the min and max.
  6711.                 float $min = getMinVal( $bdt, $attrName );
  6712.                 float $max = getMaxVal( $bdt, $attrName );
  6713.                 if ( $dataType == "double" )
  6714.                 {
  6715.                     if ( $newFloatVal > $max )
  6716.                         $newFloatVal = $max;
  6717.                     if ( $newFloatVal < $min )
  6718.                         $newFloatVal = $min;
  6719.                 }
  6720.                 else
  6721.                 {
  6722.                     if ( $newIntVal > $max )
  6723.                         $newIntVal = $max;
  6724.                     if ( $newIntVal < $min )
  6725.                         $newIntVal = $min;
  6726.                 }
  6727.             }
  6728.  
  6729.             $cmd = "polyBlindData -id " + $id + " -at \"" + $assocType;
  6730.             $cmd += "\" -ldn \"" + $attrName + "\" ";
  6731.             if ( $dataType == "double" )
  6732.                 $cmd += "-dbd " + $newFloatVal;
  6733.             else
  6734.                 $cmd += "-ind " + $newIntVal;
  6735.             $cmd += " " + $comp;
  6736. //            print( $cmd + "\n" );
  6737.             eval( $cmd );
  6738.         }
  6739.     }
  6740. }
  6741.  
  6742. // This gets called when the 'apply' button is hit, or on mouse up
  6743. // when the attribute paint tool is working.
  6744. // Figures out things like component selection 
  6745. global proc bdeApplyData()
  6746. {    
  6747.     string $parent = "bdeSingleApplyLayout";
  6748.  
  6749.     string $selected[] = `ls -sl`;
  6750.     if ( size( $selected ) == 0 )
  6751.         return;
  6752.  
  6753.     string $bdt = getSelectedApplyBdt();
  6754.     if ( $bdt == "" )
  6755.         return;
  6756.     int $id = getId( $bdt );
  6757.  
  6758.     string $controlName = "bdeAssocType" + $id;
  6759.     string $assocType = `optionMenu -q -v $controlName`;
  6760.  
  6761.     string $control = "bdeApplyType" + $id;
  6762.     string $applyType = `optionMenu -q -v $control`;
  6763.  
  6764.     // Dynamic stuff does the conversions implicitly.
  6765.     if ( $assocType == "object" )
  6766.     {
  6767.         // bdeApplyDynamicAttr( $bdt, $applyType );
  6768.         applyAbsolute( $bdt );
  6769.         if ( `checkBox -q -v bdeColorOnApply` )
  6770.             bdeDoQueryColor( 1 );
  6771.         return;
  6772.     }
  6773.     else 
  6774.     // Convert to desired assocType and do the apply. 
  6775.     // Let's hope this is what's desired from the user
  6776.     // If not, comment out this code...
  6777.     { 
  6778.         string $origSel[] = `ls -sl`;
  6779.         string $newSel[] = convList( $origSel, $assocType );
  6780.         string $select = "select -r ";
  6781.         for ( $sel in $newSel )
  6782.             $select += "\"" + $sel + "\" ";
  6783.         eval $select;
  6784.     }
  6785.     
  6786.     if ( "Absolute" == $applyType )
  6787.         applyAbsolute( $bdt );
  6788.     else 
  6789.         applyRelative( $bdt, $applyType, $assocType );
  6790.  
  6791.     if ( `checkBox -q -v bdeColorOnApply` )
  6792.         bdeColor();
  6793. }
  6794.  
  6795. // We just turn off the mode. This removes the
  6796. // false coloring from all of the poly components.
  6797. global proc bdeRemoveColor()
  6798. {
  6799.     polyColorBlindData -efc 0;
  6800. }
  6801.  
  6802. // Call this so the scriptJob script doesn't keep getting
  6803. // called even though we don't care about refreshing the viewSelected tab.
  6804. global proc bdeKillViewSelectedSJ()
  6805. {
  6806.     global int $bdeVSSJ;
  6807.  
  6808.     if ( $bdeVSSJ == -1 )
  6809.         return;
  6810.  
  6811.     scriptJob -kill $bdeVSSJ;
  6812.     $bdeVSSJ = -1;
  6813. }
  6814.  
  6815. global proc bdeStartViewSelectedSJ()
  6816. {
  6817.     global int $bdeVSSJ;
  6818.  
  6819.     if ( $bdeVSSJ != -1 )
  6820.         return;
  6821.  
  6822.     $bdeVSSJ = `scriptJob -event "SelectionChanged" bdeRefreshViewSelected`;
  6823. }
  6824.  
  6825. // Fix up the buttons (enabling/disabling as appropriate),
  6826. // rebuild the textscroll lists, popups, etc.
  6827. global proc bdeRebuild()
  6828. {    
  6829.     bdeKillViewSelectedSJ();
  6830.  
  6831.     bdeRebuildTextScrollLists();
  6832.  
  6833.     bdeRebuildPopups();
  6834.  
  6835.     int $tab = `tabLayout -q -sti bdeMainTabLayout`;
  6836.     if ( 1 == $tab ) // Apply!
  6837.     {
  6838.         // Fix buttons: Apply and Cancel only
  6839.         button -e -en true bdeApplyButton;
  6840.         button -e -en false bdeSetColorButton;
  6841.         button -e -en false bdeQueryButton;        
  6842.     }
  6843.     else if ( 2 == $tab ) // Color/Query
  6844.     {
  6845.         button -e -en false bdeApplyButton;
  6846.         button -e -en true bdeSetColorButton;
  6847.         button -e -en true bdeQueryButton;        
  6848.     }
  6849.     else if ( 3 == $tab ) // View selected
  6850.     {
  6851. //        bdeRebuildViewSelected();
  6852.         bdeStartViewSelectedSJ();
  6853.  
  6854.         button -e -en false bdeApplyButton;
  6855.         button -e -en false bdeSetColorButton;
  6856.         button -e -en false bdeQueryButton;
  6857.  
  6858.         bdeRefreshViewSelected();
  6859.     }
  6860.     else if ( 4 == $tab ) // Template editor
  6861.     {
  6862.         button -e -en false bdeApplyButton;
  6863.         button -e -en false bdeSetColorButton;
  6864.         button -e -en false bdeQueryButton;
  6865.  
  6866. //        bdeNewTemplate( true );
  6867.     }
  6868. }
  6869.  
  6870. // This was copied from initContexts.mel
  6871. //
  6872. proc rememberCtxSettings( string $ctxName )
  6873. //
  6874. // This method sees if an optionVar has been defined
  6875. // for the tool.  If it has, the string it contains
  6876. // is evaluated to set the tool settings.  SuperContexts
  6877. // should not be saved this way, since they have no
  6878. // particular settings.
  6879. //
  6880. {
  6881.     if ( `optionVar -exists $ctxName` ){
  6882.         string $cmd = `optionVar -q $ctxName`;
  6883.         catch( `eval($cmd)` );
  6884.     } else {
  6885.         // create an empty option var so that this
  6886.         // will be saved.
  6887.         optionVar -sv $ctxName "";
  6888.     }
  6889. }
  6890.  
  6891.  
  6892. global proc bdeFacetMask()
  6893. {
  6894.     setComponentPickMask "Facet" true;
  6895. }
  6896.  
  6897. global proc bdeVertexMask()
  6898. {
  6899.     setComponentPickMask "Point" true;
  6900. }
  6901.  
  6902. // Paint on the values.
  6903. global proc bdePaintValues()
  6904. {
  6905.     string $bdt = getSelectedApplyBdt();
  6906.     if ( ""== $bdt )
  6907.     {
  6908.         warning( "You must select a blind data id before painting" );
  6909.         return;
  6910.     }
  6911.  
  6912.     int $id = getId( $bdt );
  6913.     string $controlName = "bdeAssocType" + $id;
  6914.     string $assocType = `optionMenu -q -v $controlName`;
  6915.     string $preStrokeCmd;
  6916.  
  6917.     // Shouldn't be too hard to fix things up for object (dyn attr) painting
  6918.     if ( $assocType == "object" )
  6919.     {
  6920.         warning( "Paint will only work on face and vertex blind data" );
  6921.         return;
  6922.     }
  6923.     else if ( $assocType == "vertex" )
  6924.         $preStrokeCmd = "bdeVertexMask";
  6925.     else if ( $assocType == "face" )
  6926.         $preStrokeCmd = "bdeFacetMask";
  6927.  
  6928.     global string $bdeBrushToolCtx;
  6929.  
  6930.     // Set the ToolContext up...
  6931.     if ( $bdeBrushToolCtx == "" ) 
  6932.     {
  6933.         // This xpm doesn't show up on NT...
  6934.         $bdeBrushToolCtx = 
  6935.             `eval "artSelectCtx -i1 \"paintVertexColour.xpm\"        \
  6936.             -ads false                                                \
  6937.             bdeBrushToolCtx"`;
  6938.         rememberCtxSettings $bdeBrushToolCtx;
  6939.     }
  6940.  
  6941.     string    $cmd;
  6942.  
  6943.     $cmd  = "artSelectCtx -e";
  6944.     $cmd += " -bsc " + $preStrokeCmd;
  6945.     $cmd += " -asc bdeApplyData";
  6946.     $cmd +=    " " + $bdeBrushToolCtx;
  6947.     eval $cmd;
  6948.  
  6949.     setToolTo $bdeBrushToolCtx;
  6950.     // I think this isn't working even if this button exists???
  6951.     // Anyway, if this is bugging you comment it out, and uncomment the
  6952.     // paintOptionsOptions button code in the AddCallback
  6953.     if ( !`button -q -ex bdePaintOptions` )
  6954.         toolPropertyWindow;
  6955. }
  6956.  
  6957. global proc bdePaintOptions()
  6958. {
  6959.     toolPropertyWindow;
  6960. }
  6961.  
  6962. global proc bdeClosedWindow()
  6963. {
  6964.     polyColorBlindData -enableFalseColor 0;
  6965. }
  6966.  
  6967. // Not used anymore
  6968. global proc bdeForceRefresh( string $windowName )
  6969. {
  6970.     if ( `window -ex $windowName` )
  6971.         bdeForceRebuild();
  6972. }
  6973.  
  6974. // The 'main' of this script. It registers the
  6975. // panel type if it doesn't already exist, and then
  6976. // creates a torn off version of the panel. Once it's registered,
  6977. // it can be pulled up like a regular panel.
  6978. global proc blindDataEditor()
  6979. {
  6980.     if ( !`scriptedPanelType -q -ex blindDataEditor` )
  6981.     {
  6982.         scriptedPanelType
  6983.             -createCallback    bdeCreateCallback
  6984.             -initCallback      bdeInitCallback
  6985.             -addCallback       bdeAddCallback
  6986.             -removeCallback    bdeRemoveCallback
  6987.             -deleteCallback    bdeDeleteCallback
  6988.             -unique true
  6989.             blindDataEditor;
  6990.     }
  6991.  
  6992.     tearOffPanel "Blind Data Editor" "blindDataEditor" 1;
  6993. }
  6994.